home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UGridView.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  111.1 KB  |  3,823 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UGridView.cp 
  3. // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UGRIDVIEW__
  7. #include "UGridView.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UADORNERS__
  13. #include "UAdorners.h"
  14. #endif
  15.  
  16. #ifndef __UDEBUG__
  17. #include "UDebug.h"
  18. #endif
  19.  
  20. #if qDrag
  21. #ifndef __UDISPATCHER__
  22. #include "UDispatcher.h"
  23. #endif
  24. #endif
  25.  
  26. #if qDrag
  27. #ifndef __UDRAGDROP__
  28. #include "UDragDrop.h"
  29. #endif
  30. #endif
  31.  
  32. #ifndef __UGEOMETRY__
  33. #include "UGeometry.h"
  34. #endif
  35.  
  36. #ifndef __UMACAPPGLOBALS__
  37. #include "UMacAppGlobals.h"
  38. #endif
  39.  
  40. #ifndef __UMACAPPUTILITIES__
  41. #include "UMacAppUtilities.h"
  42. #endif
  43.  
  44. #ifndef __UMEMORY__
  45. #include "UMemory.h"
  46. #endif
  47.  
  48. #ifndef __USTREAM__
  49. #include "UStream.h"
  50. #endif
  51.  
  52. // Toolbox
  53.  
  54. #ifndef __ERRORS__
  55. #include <Errors.h>
  56. #endif
  57.  
  58. #ifndef __FONTS__
  59. #include <Fonts.h>
  60. #endif
  61.  
  62. #ifndef __PACKAGES__
  63. #include <Packages.h>
  64. #endif
  65.  
  66. #ifndef __TOOLUTILS__
  67. #include <ToolUtils.h>
  68. #endif
  69.  
  70. // ANSI
  71.  
  72. #ifndef __STDIO__
  73. #include <stdio.h>
  74. #endif
  75.  
  76. #ifndef __STDLIB__
  77. #include <stdlib.h>
  78. #endif
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    These "private" globals have extern interfaces. 
  82.  
  83. RgnHandle pPixelsToHighlight;
  84. RgnHandle pPreviousSelection;
  85. RgnHandle pDifference;
  86. RgnHandle pVisibleCells;
  87. RgnHandle pInvalidateRgn;
  88.  
  89.  
  90. //========================================================================================
  91. // GLOBAL Procedures
  92. //========================================================================================
  93. #undef Inherited
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // InitUGridView: 
  97. //----------------------------------------------------------------------------------------
  98. #pragma segment GVInit
  99.  
  100. void InitUGridView()
  101. {
  102. #if qTemplateViews
  103.     {
  104.         MA_REGISTER_SIGNATURE(TGridView, kStdGridView);
  105.         MA_REGISTER_SIGNATURE(TTextGridView, kStdTextGridView);
  106.         MA_REGISTER_SIGNATURE(TTextListView, kStdTextListView);
  107.     }
  108. #endif
  109.  
  110.     pPixelsToHighlight = MakeNewRgn();
  111.     pPreviousSelection = MakeNewRgn();
  112.     pDifference = MakeNewRgn();
  113.     pVisibleCells = MakeNewRgn();
  114.     pInvalidateRgn = MakeNewRgn();
  115.     gUGridViewInitialized = TRUE;
  116. }
  117.  
  118.  
  119. //========================================================================================
  120. // CLASS TRunArray
  121. //========================================================================================
  122. #undef Inherited
  123. #define Inherited TObject
  124.  
  125. #pragma segment GVOpen
  126. MA_DEFINE_CLASS_M1(TRunArray,
  127.                    Inherited);
  128.  
  129. //----------------------------------------------------------------------------------------
  130. // TRunArray constructor
  131. //----------------------------------------------------------------------------------------
  132. #pragma segment GVOpen
  133.  
  134. TRunArray::TRunArray() :
  135.     fChunks(NULL),
  136.     fLastChunk(0),
  137.     fLastIndex(1),
  138.     fLastItem(0),
  139.     fLastTotal(0),
  140.     fNoOfChunks(0),
  141.     fNoOfItems(0),
  142.     fTotal(0)
  143. {
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // TRunArray::IRunArray: 
  148. //----------------------------------------------------------------------------------------
  149. #pragma segment GVOpen
  150.  
  151. void TRunArray::IRunArray()
  152. {
  153.     IObject();
  154.  
  155.     FailInfo fi;
  156.     Try(fi)
  157.     {
  158.         fChunks = new TDynamicArray;
  159.         fChunks->IDynamicArray(0, sizeof(RunArrayChunk));
  160.         fi.Success();
  161.     }
  162.     else                                        // Recover
  163.     {
  164.         Free();
  165.         fi.ReSignal();
  166.     }
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. // TRunArray::Free: 
  171. //----------------------------------------------------------------------------------------
  172. #pragma segment GVClose
  173.  
  174. TRunArray::~TRunArray()
  175. {
  176.     fChunks = (TDynamicArray*)FreeIfObject(fChunks);// Blow chunks
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. // TRunArray::DeleteItems: 
  181. //----------------------------------------------------------------------------------------
  182. #pragma segment GVNonRes
  183.  
  184. void TRunArray::DeleteItems(short firstItem,
  185.                             short noOfItems)
  186. {
  187.     short num;
  188.     long theTotal;
  189.     short index;
  190.  
  191.     if (!FindChunk(firstItem, num, index, theTotal))
  192.     {
  193. #if qDebug
  194.         CStr255 theString;
  195.         ConcatNumber("Unable to find chunk for item ", firstItem, theString);
  196.         ProgramBreak(theString);
  197. #endif
  198.     }
  199.     else
  200.     {
  201.         for (short i = 1; i <= noOfItems; ++i)
  202.         {
  203.             fTotal -= ChunkAt(num).value;
  204.  
  205.             --ChunkAt(num).count;
  206.  
  207.             if (ChunkAt(num).count < index)
  208.             {
  209.                 index = 1;
  210.                 if (ChunkAt(num).count == 0)
  211.                 {
  212.                     // need to delete that chunk 
  213.                     fChunks->DeleteElementsAt(num + 1, 1); // TDynamicArrays are one based (except for [] operator)
  214.                     --fNoOfChunks;
  215.  
  216.                     // Thanks JDR 10/28/89 
  217.                     // see if we can consolidate chunks 
  218.                     if ((num > 0) && (num < fNoOfChunks) && (ChunkAt(num - 1).value == ChunkAt(num).value))
  219.                     {
  220.                         index = ChunkAt(num - 1).count + 1;
  221.                         ChunkAt(num - 1).count += ChunkAt(num).count;
  222.                         // need to delete that chunk 
  223.                         fChunks->DeleteElementsAt(num + 1, 1); // TDynamicArrays are one based (except for [] operator)
  224.                         --num;
  225.                         --fNoOfChunks;
  226.                     }
  227.                 }
  228.                 else
  229.                     ++num;
  230.             }
  231.         }
  232.  
  233.         fNoOfItems -= noOfItems;
  234.  
  235.         // reset the cache 
  236.         fLastItem = 0;
  237.         fLastChunk = 0;
  238.         fLastTotal = 0;
  239.         fLastIndex = 1;
  240.     }
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. // TRunArray::FindChunk: 
  245. //----------------------------------------------------------------------------------------
  246. #pragma segment GVRes
  247.  
  248. Boolean TRunArray::FindChunk(short item,
  249.                              short& chunk,
  250.                              short& indexInChunk,
  251.                              long& theTotal)
  252. {
  253.     Boolean result = FALSE;
  254.  
  255.     short thisItem;
  256.     short count;
  257.     short delta;
  258.  
  259.     if ((fNoOfChunks <= 0) || (item > fNoOfItems) || (item <= 0))
  260.     {
  261.         chunk = 0;
  262.         theTotal = 0;
  263.         indexInChunk = 0;
  264.         item = 0;
  265.     }
  266.     else if (item == fLastItem)
  267.     {
  268.         // check for the very easy case 
  269.         chunk = fLastChunk;
  270.         theTotal = fLastTotal;
  271.         indexInChunk = fLastIndex;
  272.  
  273.         result = TRUE;
  274.     }
  275.     else
  276.     {
  277.         delta = abs(item - fLastItem);
  278.  
  279.         if ((delta >= item) || (item <= ChunkAt(0).count))
  280.         {
  281.             // start from the first chunk 
  282.             chunk = 0;
  283.             theTotal = 0;
  284.             thisItem = 0;
  285.         }
  286.         else if (delta > (fNoOfItems - item + 1))
  287.         {
  288.             // start from the end chunk 
  289.             chunk = fNoOfChunks - 1;
  290.             count = ChunkAt(chunk).count;
  291.             theTotal = fTotal - (count * ChunkAt(chunk).value);
  292.             thisItem = fNoOfItems - count;
  293.         }
  294.         else
  295.         {                                        // start from the previous values 
  296.             chunk = fLastChunk;
  297.             theTotal = fLastTotal;
  298.             thisItem = fLastItem - fLastIndex;
  299.         }
  300.  
  301.         if (item > thisItem)
  302.         {
  303.             while ((thisItem + ChunkAt(chunk).count) < item)
  304.             {
  305.                 count = ChunkAt(chunk).count;
  306.                 theTotal += count * ChunkAt(chunk).value;
  307.                 thisItem += count;
  308.                 ++chunk;
  309.             }
  310.         }
  311.         else
  312.         {
  313.             do
  314.             {
  315.                 --chunk;
  316.                 count = ChunkAt(chunk).count;
  317.                 theTotal -= count * ChunkAt(chunk).value;
  318.                 thisItem -= count;
  319.             } while (thisItem >= item);
  320.         }
  321.         indexInChunk = item - thisItem;
  322.  
  323.         result = TRUE;
  324.     }
  325.     // cache the last values 
  326.     fLastItem = item;
  327.     fLastChunk = chunk;
  328.     fLastTotal = theTotal;
  329.     fLastIndex = indexInChunk;
  330.  
  331.     return result;
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. // TRunArray::FindItem: 
  336. //----------------------------------------------------------------------------------------
  337. #pragma segment GVRes
  338.  
  339. short TRunArray::FindItem(long theTotal)
  340. {
  341.     short result = 0;
  342.  
  343.     if ((theTotal >= 0) && (theTotal <= fTotal) && (fNoOfChunks > 0))
  344.         if (fNoOfChunks == 1)
  345.         {
  346.             if (ChunkAt(0).value > 0)
  347.                 result = (short)Min((theTotal / ChunkAt(0).value) + 1, fNoOfItems);//!!! Cast
  348.         }
  349.         else if (theTotal == 0)
  350.             result = 1;
  351.         else
  352.         {
  353.             ++theTotal;
  354.             short runningCount = 0;
  355.             for (short i = 0; i <= fNoOfChunks - 1; ++i)
  356.             {
  357.                 RunArrayChunk chunk = ChunkAt(i);
  358.  
  359.                 theTotal -= chunk.value * chunk.count;
  360.                 runningCount += chunk.count;
  361.                 if (theTotal <= 0)
  362.                 {
  363.                     result = (short)(runningCount + (theTotal / chunk.value));//!!! Cast
  364.                     return result;
  365.                 }
  366.             }
  367.             result = fNoOfItems;
  368.         }
  369.  
  370.     return result;
  371. }
  372.  
  373. //----------------------------------------------------------------------------------------
  374. // TRunArray::GetValue: 
  375. //----------------------------------------------------------------------------------------
  376. #pragma segment GVRes
  377.  
  378. short TRunArray::GetValue(short item)
  379. {
  380.     short returnVal = 0;
  381.  
  382.     short num;
  383.     long theTotal;
  384.     short index;
  385.  
  386.     if (fNoOfChunks == 1)
  387.         returnVal = ChunkAt(0).value;
  388.     else if (FindChunk(item, num, index, theTotal))
  389.         returnVal = ChunkAt(num).value;
  390.  
  391.     return returnVal;
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. // TRunArray::InsertItems: 
  396. //----------------------------------------------------------------------------------------
  397. #pragma segment GVRes
  398.  
  399. void TRunArray::InsertItems(short firstItem,
  400.                             short noOfItems,
  401.                             short value)
  402. {
  403.     short num;
  404.     long theTotal;
  405.     short index;
  406.  
  407.     // Check if we can just increment the last size count 
  408.     if ((firstItem > fNoOfItems) && (fNoOfChunks > 0) && (ChunkAt(fNoOfChunks - 1).value == value))
  409.         ChunkAt(fNoOfChunks - 1).count += noOfItems;
  410.  
  411.     // check if we can increment any size count 
  412.     else if (FindChunk(firstItem, num, index, theTotal) && (ChunkAt(num).value == value))
  413.         ChunkAt(num).count += noOfItems;
  414.  
  415.     // check if this would actually fit as the last item in the previous chunk 
  416.     // Thanks Martin Frické, 10/31/89
  417.     else if ((num > 0) && (index == 1) && (ChunkAt(num - 1).value == value))
  418.         ChunkAt(num - 1).count += noOfItems;
  419.  
  420.     // We need to create a new chunk, possibly two 
  421.     else
  422.     {
  423.         struct
  424.         {
  425.             RunArrayChunk chunk1;
  426.             RunArrayChunk chunk2;
  427.         } tempChunks;
  428.  
  429.         tempChunks.chunk1.value = value;
  430.         tempChunks.chunk1.count = noOfItems;
  431.  
  432.         if ((index <= 1) || (firstItem > fNoOfItems))
  433.         {
  434.             // need to add one chunk 
  435.             if (firstItem > fNoOfItems)
  436.                 num = fNoOfChunks;                // add a row on the end 
  437.  
  438.             fChunks->InsertElementsBefore(num + 1, &tempChunks, 1); // TDynamicArrays are one based (except for [] operator)
  439.             ++fNoOfChunks;
  440.         }
  441.         else
  442.         {
  443.             // need to add two 
  444.             tempChunks.chunk2.count = ChunkAt(num).count - index + 1;
  445.             tempChunks.chunk2.value = ChunkAt(num).value;
  446.             ChunkAt(num).count = index - 1;
  447.  
  448.             fChunks->InsertElementsBefore(num + 1 + 1, &tempChunks, 2); // TDynamicArrays are one based (except for [] operator)
  449.             fNoOfChunks += 2;
  450.         }
  451.     }
  452.  
  453.     // reset the cache 
  454.     fLastItem = 0;
  455.     fLastChunk = 0;
  456.     fLastTotal = 0;
  457.     fLastIndex = 1;
  458.  
  459.     fNoOfItems += noOfItems;
  460.     fTotal += noOfItems * value;
  461. }
  462.  
  463. //----------------------------------------------------------------------------------------
  464. // TRunArray::SumValues: 
  465. //----------------------------------------------------------------------------------------
  466. #pragma segment GVRes
  467.  
  468. long TRunArray::SumValues(short firstItem,
  469.                           short noOfItems)
  470. {
  471.     long result = 0;
  472.  
  473.     short chunk;
  474.     short indexInChunk;
  475.     long total;
  476.  
  477.     if (fNoOfChunks == 1)
  478.         result = noOfItems * ChunkAt(0).value;
  479.     else if (firstItem == 1)
  480.     {
  481.         if (FindChunk(noOfItems, chunk, indexInChunk, total))
  482.             result = total + (indexInChunk * ChunkAt(chunk).value);
  483.     }
  484.     else if (FindChunk(firstItem, chunk, indexInChunk, total))
  485.     {
  486.         long precedingTotal = total + ((indexInChunk - 1) * ChunkAt(chunk).value);
  487.         if (FindChunk(firstItem + noOfItems - 1, chunk, indexInChunk, total))
  488.             result = total + (indexInChunk * (ChunkAt(chunk).value) - precedingTotal);
  489.     }
  490.  
  491.     return result;
  492. }
  493.  
  494.  
  495. //========================================================================================
  496. // CLASS TGridView
  497. //========================================================================================
  498. #undef Inherited
  499. #define Inherited TView
  500.  
  501. #pragma segment GVOpen
  502. MA_DEFINE_CLASS_M1(TGridView,
  503.                    Inherited);
  504.  
  505. //----------------------------------------------------------------------------------------
  506. // TGridView constructor
  507. //----------------------------------------------------------------------------------------
  508. #pragma segment GVOpen
  509.  
  510. TGridView::TGridView() :
  511.     fNumOfRows(0),
  512.     fNumOfCols(0),
  513.  
  514.     fAdornRows(FALSE),
  515.     fAdornCols(FALSE),
  516.     fRowInset(0),
  517.     fColInset(0),
  518.     fColWidths(NULL),
  519.     fRowHeights(NULL),
  520.  
  521.     fSelections(NULL),
  522.     fHLRegion(NULL),
  523.     fTemporarySelections(NULL),
  524.  
  525.     fSingleSelection(TRUE)
  526. {
  527. }
  528. // TGridView::TGridView
  529.  
  530. //----------------------------------------------------------------------------------------
  531. // TGridView::IGridView: 
  532. //----------------------------------------------------------------------------------------
  533. #pragma segment GVOpen
  534.  
  535. void TGridView::IGridView(TDocument* itsDocument,
  536.                           // Its document 
  537.                           TView* itsSuperView,
  538.                           // Its parent view 
  539.                           const VPoint& itsLocation,
  540.                           // Top, Left in parent's coords 
  541.                           const VPoint& itsSize,
  542.                           // Ignored for SizeVariable
  543.                           SizeDeterminer itsHSizeDet,
  544.                           SizeDeterminer itsVSizeDet,
  545.                           // Size determiners 
  546.                           short numOfRows,
  547.                           // Number of rows initially 
  548.                           short numOfCols,
  549.                           // Number of columns initially 
  550.                           short rowHeight,
  551.                           // Height of initial rows 
  552.                           short colWidth,
  553.                           // Height of initial columns 
  554.                           Boolean adornRows,
  555.                           // Adornment for Rows? 
  556.                           Boolean adornCols,
  557.                           // Adornment for Columns? 
  558.                           short rowInset,
  559.                           // horizontal space between cells 
  560.                           short colInset,
  561.                           // vertical space between cells 
  562.                           Boolean singleSelection)// single cell selection? 
  563.  
  564. {
  565. #if qDebug
  566.     if (!gUGridViewInitialized)
  567.     {
  568.         ProgramBreak("InitUGridView must be called before creating a grid view.");
  569.         Failure(noErr, 0);
  570.     }
  571. #endif
  572.  
  573.     IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  574.  
  575.     fAdornRows = adornRows;
  576.     fAdornCols = adornCols;
  577.  
  578.     // Make sure the insets are evenly divided between top/bottom or left/right 
  579.     fRowInset = rowInset;
  580.     if (odd(rowInset))
  581.         ++fRowInset;
  582.  
  583.     fColInset = colInset;
  584.     if (odd(colInset))
  585.         ++fColInset;
  586.  
  587.     FailInfo fi;
  588.     Try(fi)
  589.     {
  590.         TRunArray * aRunArray = new TRunArray;
  591.         aRunArray->IRunArray();
  592.         fColWidths = aRunArray;
  593.  
  594.         aRunArray = new TRunArray;
  595.         aRunArray->IRunArray();
  596.         fRowHeights = aRunArray;
  597.  
  598.         fSelections = MakeNewRgn();                // region to hold current selections 
  599.         fHLRegion = MakeNewRgn();                // region to hold current highlighted cells 
  600.         fTemporarySelections = MakeNewRgn();    // used by SetSelectionRect 
  601.  
  602.         fSingleSelection = singleSelection;
  603.  
  604.         if (numOfCols > 0)
  605.             InsColFirst(numOfCols, colWidth);
  606.         if (numOfRows > 0)
  607.             InsRowFirst(numOfRows, rowHeight);
  608.  
  609.         AddAdorner(gSelectionAdorner, kDrawView, FALSE);// wants DoHighlightSelection 
  610.  
  611.         fi.Success();
  612.     }
  613.     else                                        // Recover
  614.     {
  615.         Free();
  616.         fi.ReSignal();
  617.     }
  618.  
  619. }
  620.  
  621. //----------------------------------------------------------------------------------------
  622. // TGridView::Clone: 
  623. //----------------------------------------------------------------------------------------
  624. #pragma segment GVNonRes
  625.  
  626. TObject* TGridView::Clone()                        // override 
  627. {
  628.     MAVolatileInit(TGridView * , aClonedGridView, (TGridView *)(Inherited::Clone()));
  629.  
  630.     aClonedGridView->fNumOfCols = 0;
  631.     aClonedGridView->fNumOfRows = 0;
  632.     aClonedGridView->fColWidths = NULL;            // For failure handling
  633.     aClonedGridView->fRowHeights = NULL;
  634.  
  635.     // This code is neccessary because MacApp does not support cloning properly
  636.     // It could be replaced with TGridView(inputView).fColWidths.Clone otherwise
  637.  
  638.     FailInfo fi;
  639.     Try(fi)
  640.     {
  641.         TRunArray * aRunArray = new TRunArray;
  642.         aRunArray->IRunArray();
  643.         aClonedGridView->fColWidths = aRunArray;
  644.  
  645.         aRunArray = new TRunArray;
  646.         aRunArray->IRunArray();
  647.         aClonedGridView->fRowHeights = aRunArray;
  648.  
  649.         aClonedGridView->fSelections = MakeNewRgn();// region to hold current selections 
  650.         aClonedGridView->fHLRegion = MakeNewRgn();// region to hold current highlighted cells 
  651.         aClonedGridView->fTemporarySelections = MakeNewRgn();// used by SetSelectionRect 
  652.  
  653.         if (fNumOfCols > 0)
  654.             aClonedGridView->InsColFirst(fNumOfCols, GetColWidth(1));
  655.         if (fNumOfRows > 0)
  656.             aClonedGridView->InsRowFirst(fNumOfRows, GetRowHeight(1));
  657.  
  658.         fi.Success();
  659.     }
  660.     else                                        // Recover
  661.     {
  662.         aClonedGridView->Free();
  663.         fi.ReSignal();
  664.     }
  665.  
  666.     return aClonedGridView;
  667. }
  668.  
  669. //----------------------------------------------------------------------------------------
  670. // TGridView::Free: 
  671. //----------------------------------------------------------------------------------------
  672. #pragma segment GVClose
  673.  
  674. TGridView::~TGridView()
  675. {
  676.     // Dispose regions 
  677.     fSelections = DisposeIfRgnHandle(fSelections);
  678.     fHLRegion = DisposeIfRgnHandle(fHLRegion);
  679.     fTemporarySelections = DisposeIfRgnHandle(fTemporarySelections);
  680.  
  681.     fColWidths = (TRunArray *)(FreeIfObject(fColWidths));
  682.     fRowHeights = (TRunArray *)(FreeIfObject(fRowHeights));
  683. }
  684.  
  685. //----------------------------------------------------------------------------------------
  686. // TGridView::GetStandardSignature: 
  687. //----------------------------------------------------------------------------------------
  688. #pragma segment GVWriteResource
  689.  
  690. IDType TGridView::GetStandardSignature()        // override 
  691. {
  692.     return kStdGridView;
  693. }
  694.  
  695. //----------------------------------------------------------------------------------------
  696. // TGridView::ReadFields: 
  697. //----------------------------------------------------------------------------------------
  698. #pragma segment GVReadResource
  699.  
  700. void TGridView::ReadFields(TStream* aStream)    // override 
  701. {
  702. #if qDebug
  703.     if (!gUGridViewInitialized)
  704.     {
  705.         ProgramBreak("InitUGridView must be called before creating a grid view.");
  706.         Failure(noErr, 0);
  707.     }
  708. #endif
  709.  
  710.     short numOfCols,
  711.     numOfRows,
  712.     colWidth,
  713.     rowHeight;
  714.  
  715.     Inherited::ReadFields(aStream);
  716.  
  717.     FailInfo fi;
  718.     Try(fi)
  719.     {
  720.         numOfRows = aStream->ReadInteger();
  721.         numOfCols = aStream->ReadInteger();
  722.  
  723.         rowHeight = aStream->ReadInteger();
  724.         colWidth = aStream->ReadInteger();
  725.  
  726.         fRowInset = aStream->ReadInteger();
  727.         fColInset = aStream->ReadInteger();
  728.  
  729.         fAdornRows = aStream->ReadBoolean();
  730.         fAdornCols = aStream->ReadBoolean();
  731.  
  732.         fSingleSelection = aStream->ReadBoolean();
  733.  
  734.         if (odd(fRowInset))
  735.             ++fRowInset;
  736.  
  737.         if (odd(fColInset))
  738.             ++fColInset;
  739.  
  740.         TRunArray * aRunArray = new TRunArray;
  741.         aRunArray->IRunArray();
  742.         fColWidths = aRunArray;
  743.  
  744.         aRunArray = new TRunArray;
  745.         aRunArray->IRunArray();
  746.         fRowHeights = aRunArray;
  747.  
  748.         fSelections = MakeNewRgn();                // region to hold current selections 
  749.         fHLRegion = MakeNewRgn();                // region to hold current highlighted cells 
  750.         fTemporarySelections = MakeNewRgn();    // used by SetSelectionRect 
  751.  
  752.         if (numOfCols > 0)
  753.             InsColFirst(numOfCols, colWidth);
  754.         if (numOfRows > 0)
  755.             InsRowFirst(numOfRows, rowHeight);
  756.  
  757.         fi.Success();
  758.     }
  759.     else                                        // Recover
  760.     {
  761.         Free();
  762.         fi.ReSignal();
  763.     }
  764. }
  765.  
  766. //----------------------------------------------------------------------------------------
  767. // TGridView::WriteFields: 
  768. //----------------------------------------------------------------------------------------
  769. #pragma segment GVWriteResource
  770.  
  771. void TGridView::WriteFields(TStream* aStream)    // override 
  772. {
  773.     short rowHeight = 0,
  774.     colWidth = 0;
  775.  
  776.     Inherited::WriteFields(aStream);
  777.  
  778.     if (fNumOfRows > 0)
  779.         rowHeight = GetRowHeight(1);
  780.  
  781.     if (fNumOfCols > 0)
  782.         colWidth = GetColWidth(1);
  783.  
  784.     aStream->WriteInteger(fNumOfRows);
  785.     aStream->WriteInteger(fNumOfCols);
  786.     aStream->WriteInteger(rowHeight);
  787.     aStream->WriteInteger(colWidth);
  788.     aStream->WriteInteger(fRowInset);
  789.     aStream->WriteInteger(fColInset);
  790.     aStream->WriteBoolean(fAdornRows);
  791.     aStream->WriteBoolean(fAdornCols);
  792.     aStream->WriteBoolean(fSingleSelection);
  793. }
  794.  
  795. //----------------------------------------------------------------------------------------
  796. // TGridView::AdornCol: 
  797. //----------------------------------------------------------------------------------------
  798. #pragma segment GVRes
  799.  
  800. void TGridView::AdornCol(short aCol,
  801.                          const VRect& area)
  802. {
  803.     PenNormal();
  804.     CRect qdRect(ViewToQDRect(area));
  805.  
  806.     MoveTo(qdRect.right, qdRect.top);
  807.     Line(0, qdRect.GetLength(vSel));
  808.     if (aCol == 1)
  809.     {
  810.         MoveToPt(qdRect[topLeft]);
  811.         Line(0, qdRect.GetLength(vSel));
  812.     }
  813. }
  814.  
  815. //----------------------------------------------------------------------------------------
  816. // TGridView::AdornRow: 
  817. //----------------------------------------------------------------------------------------
  818. #pragma segment GVRes
  819.  
  820. void TGridView::AdornRow(short aRow,
  821.                          const VRect& area)
  822. {
  823.     PenNormal();
  824.     CRect qdRect(ViewToQDRect(area));
  825.  
  826.     MoveTo(qdRect.left, qdRect.bottom);
  827.     Line(qdRect.GetLength(hSel), 0);
  828.     if (aRow == 1)
  829.     {
  830.         MoveToPt(qdRect[topLeft]);
  831.         Line(qdRect.GetLength(hSel), 0);
  832.     }
  833. }
  834.  
  835. //----------------------------------------------------------------------------------------
  836. // TGridView::CalcMinFrame: 
  837. //----------------------------------------------------------------------------------------
  838. #pragma segment GVRes
  839.  
  840. VRect TGridView::CalcMinFrame()                    // override 
  841. {
  842.     VRect minFrame(Inherited::CalcMinFrame());
  843.  
  844.     // Set the amount of room needed for that many items 
  845.     minFrame[botRight] = minFrame[topLeft] + VPoint(fColWidths->GetTotal(), fRowHeights->GetTotal());
  846.  
  847.     return minFrame;
  848. }
  849.  
  850. //----------------------------------------------------------------------------------------
  851. // TGridView::CanSelectCell: 
  852. //----------------------------------------------------------------------------------------
  853. #pragma segment GVRes
  854.  
  855. Boolean TGridView::CanSelectCell(GridCell aCell)
  856. {
  857.     return ((aCell.h >= 1) && (aCell.v >= 1) && (aCell.h <= fNumOfCols) && (aCell.v <= fNumOfRows));
  858. }
  859.  
  860. //----------------------------------------------------------------------------------------
  861. // TGridView::CellToVRect: 
  862. //----------------------------------------------------------------------------------------
  863. #pragma segment GVRes
  864.  
  865. VRect TGridView::CellToVRect(GridCell aCell) const
  866. {
  867.     VRect aRect;
  868.  
  869.     short width;
  870.     short height;
  871.  
  872.     if ((aCell.h < 1) || (aCell.v < 1) || (aCell.h > fNumOfCols) || (aCell.v > fNumOfRows))
  873.     {
  874. #if qRangeCheck && qDebugMsg
  875.         fprintf(stderr, "aCell.h == %6d fNumOfCols == %6d\n", aCell.h, fNumOfCols);
  876.         fprintf(stderr, "aCell.v == %6d fNumOfRows == %6d\n", aCell.v, fNumOfRows);
  877.         ProgramBreak("Range Check in CellToVRect");
  878. #endif
  879.  
  880.         aRect = gZeroVRect;
  881.     }
  882.     else                                        // all the params look OK 
  883.         {
  884.             width = fColWidths->GetValue(aCell.h);
  885.             if (fColWidths->fNoOfChunks == 1)
  886.                 aRect.left = width * (aCell.h - 1);
  887.             else
  888.                 aRect.left = fColWidths->SumValues(1, aCell.h - 1);
  889.             aRect.right = aRect.left + width;
  890.  
  891.             height = fRowHeights->GetValue(aCell.v);
  892.             if (fRowHeights->fNoOfChunks == 1)
  893.                 aRect.top = height * (aCell.v - 1);
  894.             else
  895.                 aRect.top = fRowHeights->SumValues(1, aCell.v - 1);
  896.             aRect.bottom = aRect.top + height;
  897.         }
  898.  
  899.     return aRect;
  900. }
  901.  
  902. //----------------------------------------------------------------------------------------
  903. // TGridView::ColToVRect: 
  904. //----------------------------------------------------------------------------------------
  905. #pragma segment GVRes
  906.  
  907. VRect TGridView::ColToVRect(short aCol,
  908.                            short numOfCols) const
  909. {
  910.     VRect aRect;
  911.     long width;
  912.     long leftEdge;
  913.  
  914.     if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
  915.     {
  916. #if qDebugMsg && qRangeCheck
  917.         fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
  918.         ProgramBreak("Range Check in ColToVRect");
  919. #endif
  920.  
  921.         aRect = gZeroVRect;
  922.     }
  923.     else                                        // all the params look OK 
  924.         {
  925.             if (fColWidths->fNoOfChunks == 1)    // only one column width 
  926.             {
  927.                 width = GetColWidth(1);
  928.                 leftEdge = width * (aCol - 1);
  929.                 width *= numOfCols;
  930.             }
  931.             else
  932.             {
  933.                 leftEdge = fColWidths->SumValues(1, aCol - 1);
  934.                 width = fColWidths->SumValues(aCol, numOfCols);
  935.             }
  936.  
  937.             aRect = VRect(leftEdge, 0, leftEdge + width, fRowHeights->GetTotal());
  938.         }
  939.  
  940.     return aRect;
  941. }
  942.  
  943. //----------------------------------------------------------------------------------------
  944. // TGridView::AddStrip: 
  945. //----------------------------------------------------------------------------------------
  946. #pragma segment GVRes
  947.  
  948. void TGridView::AddStrip(RgnHandle thePixels,
  949.                          VHSelect direction,
  950.                          short& startOfStrip,
  951.                          short endOfStrip,
  952.                          CRect& stripRect,
  953.                          short row,
  954.                          short col,
  955.                          VRect& pixels,
  956.                          VRect& previousPixels,
  957.                          CRect& prevStripRect)
  958. {
  959.     if (direction == vSel)
  960.         stripRect = CRect(col, startOfStrip, col, endOfStrip);
  961.     else
  962.         stripRect = CRect(startOfStrip, row, endOfStrip, row);
  963.  
  964. #if qDebugMsg
  965.     if (gIntenseDebugging)
  966.     {
  967.         fprintf(stderr, "Adding cells = %s\n", (const char*)stripRect);
  968.     }
  969. #endif
  970.  
  971.     pixels = previousPixels;
  972.  
  973.     if (stripRect.top != prevStripRect.top)
  974.         pixels.top = fRowHeights->SumValues(1, stripRect.top - 1);
  975.     if (stripRect.bottom != prevStripRect.bottom)
  976.     {
  977.         if (stripRect.bottom == stripRect.top)
  978.             pixels.bottom = pixels.top + fRowHeights->GetValue(stripRect.bottom);
  979.         else
  980.             pixels.bottom = fRowHeights->SumValues(1, stripRect.bottom);
  981.     }
  982.     if (stripRect.left != prevStripRect.left)
  983.         pixels.left = fColWidths->SumValues(1, stripRect.left - 1);
  984.     if (stripRect.right != prevStripRect.right)
  985.     {
  986.         if (stripRect.right == stripRect.left)
  987.             pixels.right = pixels.left + fColWidths->GetValue(stripRect.right);
  988.         else
  989.             pixels.right = fColWidths->SumValues(1, stripRect.right);
  990.     }
  991.  
  992.     previousPixels = pixels;
  993.  
  994.     CTemporaryRegion tempRgn;
  995.  
  996.     SetEmptyRgn(tempRgn);
  997.     RectRgn(tempRgn, &ViewToQDRect(pixels));
  998.     UnionRgn(tempRgn, thePixels, thePixels);
  999.  
  1000.     prevStripRect = stripRect;
  1001.     startOfStrip = 0;
  1002. }
  1003.  
  1004.  
  1005. //----------------------------------------------------------------------------------------
  1006. // TGridView::CellsToPixels: 
  1007. //----------------------------------------------------------------------------------------
  1008. void TGridView::CellsToPixels(RgnHandle theCells,
  1009.                               RgnHandle thePixels)
  1010. {
  1011.     CRect stripRect;
  1012.     GridCell aCell;
  1013.     short row,
  1014.     col;
  1015.     VRect pixels;
  1016.     VRect previousPixels;
  1017.     short startOfStrip;
  1018.  
  1019.     SetEmptyRgn(thePixels);
  1020.  
  1021.     if (!EmptyRgn(theCells) && Focus())
  1022.     {
  1023.         if ((*theCells)->rgnSize == 10)            // the region is a rectangle 
  1024.         {
  1025.             CRect cellBounds = (**theCells).rgnBBox;
  1026.             pixels = VRect(fColWidths->SumValues(1, cellBounds.left - 1), fRowHeights->SumValues(1, cellBounds.top - 1), fColWidths->SumValues(1, cellBounds.right - 1), fRowHeights->SumValues(1, cellBounds.bottom - 1));
  1027.             (*thePixels)->rgnBBox = ViewToQDRect(pixels);
  1028.         }
  1029.         else
  1030.         {
  1031.             // Reduce the cells to only those that are visible 
  1032.             CRect visibleCells;
  1033.             VRect visibleVRect(GetVisibleRect());
  1034.             visibleCells[topLeft] = VPointToLastCell(visibleVRect[topLeft]);
  1035.             visibleCells[botRight] = VPointToLastCell(visibleVRect[botRight]);
  1036.             SetRectRgn(pVisibleCells, visibleCells.left, visibleCells.top, visibleCells.right + 1, visibleCells.bottom + 1);
  1037.             SectRgn(theCells, pVisibleCells, pVisibleCells);
  1038.             CRect cellBounds = (**pVisibleCells).rgnBBox;
  1039.  
  1040.             CRect prevStripRect = gZeroRect;
  1041.             VHSelect direction = LongerSide(cellBounds);
  1042.             if (direction == vSel)
  1043.             {
  1044.                 for (col = cellBounds.left; col < cellBounds.right; ++col)
  1045.                 {
  1046.                     aCell.h = col;
  1047.                     startOfStrip = 0;
  1048.                     for (row = cellBounds.top; row < cellBounds.bottom; ++row)
  1049.                     {
  1050.                         aCell.v = row;
  1051.                         if (PtInRgn(aCell, pVisibleCells))
  1052.                         {
  1053.                             if (startOfStrip == 0)
  1054.                                 startOfStrip = row;
  1055.                         }
  1056.                         else if (startOfStrip > 0)
  1057.                             AddStrip(thePixels, direction, startOfStrip, row - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
  1058.                     }
  1059.                     if (startOfStrip > 0)
  1060.                         AddStrip(thePixels, direction, startOfStrip, cellBounds.bottom - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
  1061.                 }
  1062.             }
  1063.             else
  1064.             {
  1065.                 for (row = cellBounds.top; row < cellBounds.bottom; ++row)
  1066.                 {
  1067.                     aCell.v = row;
  1068.                     startOfStrip = 0;
  1069.                     for (col = cellBounds.left; col < cellBounds.right; ++col)
  1070.                     {
  1071.                         aCell.h = col;
  1072.                         if (PtInRgn(aCell, pVisibleCells))
  1073.                         {
  1074.                             if (startOfStrip == 0)
  1075.                                 startOfStrip = col;
  1076.                         }
  1077.                         else if (startOfStrip > 0)
  1078.                             AddStrip(thePixels, direction, startOfStrip, col - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
  1079.                     }
  1080.                     if (startOfStrip > 0)
  1081.                         AddStrip(thePixels, direction, startOfStrip, cellBounds.right - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
  1082.                 }
  1083.             }
  1084.         }
  1085.     }
  1086. }
  1087.  
  1088. //----------------------------------------------------------------------------------------
  1089. // TGridView::DoHighlightSelection: 
  1090. //----------------------------------------------------------------------------------------
  1091. #pragma segment GVRes
  1092.  
  1093. void TGridView::DoHighlightSelection(HLState fromHL,
  1094.                                      HLState toHL)// override 
  1095. {
  1096.     if (!EmptyRgn(fHLRegion))
  1097.         HighlightCells(fHLRegion, fromHL, toHL);
  1098. }
  1099.  
  1100. //----------------------------------------------------------------------------------------
  1101. // TGridView::HighlightCells: 
  1102. //----------------------------------------------------------------------------------------
  1103. #pragma segment GVRes
  1104.  
  1105. void TGridView::HighlightCells(RgnHandle theCells,
  1106.                                HLState fromHL,
  1107.                                HLState toHL)
  1108. {
  1109.     if ((fromHL != toHL) && Focus())
  1110.     {
  1111.         CellsToPixels(theCells, pPixelsToHighlight);
  1112.         SetupDrawingEnvironment();
  1113.         switch (fromHL + toHL)
  1114.         {
  1115.             case hlOffDim:
  1116.                 PenNormal();
  1117.                 PenMode(patXor);
  1118.                 UseSelectionColor();
  1119.                 FrameRgn(pPixelsToHighlight);
  1120.                 break;
  1121.             case hlOnDim:
  1122.                 {
  1123.                     CTemporaryRegion innerRgn;
  1124.                     CopyRgn(pPixelsToHighlight, innerRgn);
  1125.                     InsetRgn(innerRgn, 1, 1);
  1126.                     PenNormal();
  1127.                     UseSelectionColor();
  1128.                     InvertRgn(innerRgn);
  1129.                 }
  1130.                 break;
  1131.             case hlOffOn:
  1132.                 PenNormal();
  1133.                 UseSelectionColor();
  1134.                 InvertRgn(pPixelsToHighlight);
  1135.                 break;
  1136.         }
  1137.     }
  1138. }
  1139.  
  1140. //----------------------------------------------------------------------------------------
  1141. // TGridView::DoMenuCommand: 
  1142. //----------------------------------------------------------------------------------------
  1143. #pragma segment GVRes
  1144.  
  1145. void TGridView::DoMenuCommand(CommandNumber aCommandNumber)
  1146. {
  1147.     switch (aCommandNumber)
  1148.     {
  1149.         case cSelectAll:
  1150.             {
  1151.                 CCellIterator iter(this);
  1152.  
  1153.                 for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
  1154.                     if (CanSelectCell(aCell))
  1155.                         SelectCell(aCell, kExtend, kHighlight, kSelect);
  1156.                 break;
  1157.             }
  1158.  
  1159.         default:
  1160.             Inherited::DoMenuCommand(aCommandNumber);
  1161.             break;
  1162.     }
  1163. }
  1164.  
  1165. //----------------------------------------------------------------------------------------
  1166. // TGridView::DoMouseCommand: 
  1167. //----------------------------------------------------------------------------------------
  1168. #pragma segment GVRes
  1169.  
  1170. void TGridView::DoMouseCommand(VPoint& theMouse,
  1171.                                TToolboxEvent* event,
  1172.                                CPoint)            // override 
  1173. {
  1174.     GridCell aCell;
  1175.  
  1176.     if ((IdentifyPoint(theMouse, aCell) != badChoice) && CanSelectCell(aCell))
  1177.     {
  1178.         TCellSelectCommand * aCellSelectCommand = new TCellSelectCommand;
  1179.         aCellSelectCommand->ICellSelectCommand(this, theMouse, event->IsShiftKeyPressed(), event->IsCommandKeyPressed());
  1180.         PostCommand(aCellSelectCommand);
  1181.     }
  1182. }
  1183.  
  1184. //----------------------------------------------------------------------------------------
  1185. // TGridView::Draw: 
  1186. //----------------------------------------------------------------------------------------
  1187. #pragma segment GVRes
  1188.  
  1189. void TGridView::Draw(const VRect& area)            // override 
  1190. {
  1191.     VRect localArea(area);
  1192.  
  1193.     if ((fNumOfRows > 0) && (fNumOfCols > 0))
  1194.     {
  1195.         // make sure we have something to draw 
  1196.  
  1197.         GridCell startCell(VPointToLastCell(area[topLeft]));
  1198.         if (fAdornCols)
  1199.             startCell.h = (short)Max(1, startCell.h - 1);
  1200.         if (fAdornRows)
  1201.             startCell.v = (short)Max(1, startCell.v - 1);
  1202.         GridCell stopCell(VPointToLastCell(area[botRight]));
  1203.  
  1204.         VRect aRect(CellToVRect(startCell));
  1205.         VRect bRect(CellToVRect(stopCell));
  1206.         bRect[topLeft] = aRect[topLeft];
  1207.         localArea = bRect;
  1208.  
  1209.         GridCell startCellToDraw(startCell);
  1210.         VRect cellsArea(localArea);
  1211.         if (area.top >= aRect.bottom - (fRowInset / 2))//((fRowInset) >> 1)
  1212.         {
  1213.             ++startCellToDraw.v;
  1214.             cellsArea.top += aRect.GetLength(vSel);
  1215.         }
  1216.  
  1217.         DrawRangeOfCells(startCellToDraw, stopCell, cellsArea);
  1218.  
  1219.         if (fAdornCols)
  1220.         {
  1221.             short colWidth = 0;
  1222.             aRect = localArea;
  1223.  
  1224.             Boolean constantWidth = fColWidths->fNoOfChunks == 1;
  1225.             if (constantWidth)                    // only one width 
  1226.                 colWidth = GetColWidth(1);
  1227.  
  1228.             for (long i = startCell.h; i <= stopCell.h; ++i)
  1229.             {
  1230.                 if (constantWidth)
  1231.                     aRect.right = aRect.left + colWidth;
  1232.                 else
  1233.                     aRect.right = aRect.left + GetColWidth(i);
  1234.  
  1235.                 AdornCol(i, aRect);
  1236.                 aRect.left = aRect.right;
  1237.             }
  1238.         }
  1239.  
  1240.         if (fAdornRows)
  1241.         {
  1242.             short rowHeight = 0;
  1243.             aRect = localArea;
  1244.  
  1245.             Boolean constantHeight = fRowHeights->fNoOfChunks == 1;
  1246.             if (constantHeight)                    // only one height 
  1247.                 rowHeight = GetRowHeight(1);
  1248.  
  1249.             for (long i = startCell.v; i <= stopCell.v; ++i)
  1250.             {
  1251.                 if (constantHeight)
  1252.                     aRect.bottom = aRect.top + rowHeight;
  1253.                 else
  1254.                     aRect.bottom = aRect.top + GetRowHeight(i);
  1255.  
  1256.                 AdornRow(i, aRect);
  1257.                 aRect.top = aRect.bottom;
  1258.             }
  1259.         }
  1260.     }
  1261.  
  1262.     Inherited::Draw(localArea);
  1263. }
  1264.  
  1265. //----------------------------------------------------------------------------------------
  1266. // TGridView::DrawRangeOfCells: 
  1267. //----------------------------------------------------------------------------------------
  1268. #pragma segment GVRes
  1269.  
  1270. void TGridView::DrawRangeOfCells(GridCell startCell,
  1271.                                  GridCell stopCell,
  1272.                                  const VRect& aRect)
  1273. {
  1274.     VCoordinate colWidth;
  1275.     VCoordinate rowHeight;
  1276.  
  1277.     VRect localVRect(aRect);                    // added because argument is const
  1278.     localVRect.left += fColInset / 2;
  1279.     localVRect.top += fRowInset / 2;
  1280.  
  1281.     VCoordinate left = localVRect.left;            // save it for each iteration of for loop
  1282.  
  1283.     if (fColWidths->fNoOfChunks == 1)            // only one width 
  1284.         colWidth = GetColWidth(1);
  1285.     if (fRowHeights->fNoOfChunks == 1)            // only one height 
  1286.         rowHeight = GetRowHeight(1);
  1287.  
  1288.     CTemporaryRegion drawableRegion;
  1289.     GetDrawableRegion(drawableRegion);
  1290.  
  1291.     for (short j = startCell.v; j <= stopCell.v; ++j)
  1292.     {
  1293.         localVRect.bottom = localVRect.top - fRowInset;
  1294.         if (fRowHeights->fNoOfChunks == 1)        // only one height 
  1295.             localVRect.bottom += rowHeight;
  1296.         else
  1297.             localVRect.bottom += GetRowHeight(j);
  1298.  
  1299.         localVRect.left = left;                    // start back at the left for the next row 
  1300.  
  1301.         for (short i = startCell.h; i <= stopCell.h; ++i)
  1302.         {
  1303.             localVRect.right = localVRect.left - fColInset;
  1304.             if (fColWidths->fNoOfChunks == 1)    // only one height 
  1305.                 localVRect.right += colWidth;
  1306.             else
  1307.                 localVRect.right += GetColWidth(i);
  1308.  
  1309.             // check if the rect is drawable
  1310.             if (RectInRgn(&ViewToQDRect(localVRect), drawableRegion))
  1311.                 DrawCell(GridCell(i, j), localVRect);
  1312.  
  1313.             localVRect.left = localVRect.right + fColInset;
  1314.         }
  1315.         localVRect.top = localVRect.bottom + fRowInset;
  1316.     }
  1317. }
  1318.  
  1319. //----------------------------------------------------------------------------------------
  1320. // TGridView::DrawCell: 
  1321. //----------------------------------------------------------------------------------------
  1322. #pragma segment GVRes
  1323.  
  1324. void TGridView::DrawCell(GridCell                /* aCell */,
  1325.                          const VRect&            /* aRect */ )
  1326. {
  1327. }
  1328.  
  1329. //----------------------------------------------------------------------------------------
  1330. // TGridView::DelColAt: 
  1331. //----------------------------------------------------------------------------------------
  1332. #pragma segment GVNonRes
  1333.  
  1334. void TGridView::DelColAt(short aCol,
  1335.                          short numOfCols)
  1336. {
  1337.     if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
  1338.     {
  1339.         if (numOfCols != 0)
  1340.         {
  1341. #if qDebugMsg
  1342.             fprintf(stderr, "fNumOfCols == %1d   aCol == %1d\n", fNumOfCols, aCol);
  1343.             ProgramBreak("Range Check in DelColAt");
  1344.             return;
  1345. #endif
  1346.  
  1347.         }
  1348.     }
  1349.     else
  1350.     {
  1351.         VRect aVRect(ColToVRect((short)Max(1, aCol), (short)Max(1, fNumOfCols - aCol + 1)));//!!! cast
  1352.         fColWidths->DeleteItems(aCol, numOfCols);
  1353.         fNumOfCols -= numOfCols;
  1354.  
  1355.         AdjustFrame();
  1356.         InvalidateVRect(aVRect);
  1357.     }
  1358. }
  1359.  
  1360. //----------------------------------------------------------------------------------------
  1361. // TGridView::DelRowAt: 
  1362. //----------------------------------------------------------------------------------------
  1363. #pragma segment GVNonRes
  1364.  
  1365. void TGridView::DelRowAt(short aRow,
  1366.                          short numOfRows)
  1367. {
  1368.     if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
  1369.     {
  1370.         if (numOfRows != 0)
  1371.         {
  1372. #if qDebugMsg
  1373.             fprintf(stderr, "fNumOfRows == %1d  aRow == %1d\n", fNumOfRows, aRow);
  1374.             ProgramBreak("Range Check in DelRowAt");
  1375.             return;
  1376. #endif
  1377.  
  1378.         }
  1379.     }
  1380.     else
  1381.     {
  1382.         VRect aVRect(RowToVRect((short)Max(1, aRow), (short)Max(1, fNumOfRows - aRow + 1)));//!!! cast
  1383.         fRowHeights->DeleteItems(aRow, numOfRows);
  1384.         fNumOfRows -= numOfRows;
  1385.  
  1386.         AdjustFrame();
  1387.         InvalidateVRect(aVRect);
  1388.     }
  1389. }
  1390.  
  1391. //----------------------------------------------------------------------------------------
  1392. // TGridView::DelColFirst: 
  1393. //----------------------------------------------------------------------------------------
  1394. #pragma segment GVNonRes
  1395.  
  1396. void TGridView::DelColFirst(short numOfCols)
  1397. {
  1398.     DelColAt(1, numOfCols);
  1399. }
  1400.  
  1401. //----------------------------------------------------------------------------------------
  1402. // TGridView::DelRowFirst: 
  1403. //----------------------------------------------------------------------------------------
  1404. #pragma segment GVNonRes
  1405.  
  1406. void TGridView::DelRowFirst(short numOfRows)
  1407. {
  1408.     DelRowAt(1, numOfRows);
  1409. }
  1410.  
  1411. //----------------------------------------------------------------------------------------
  1412. // TGridView::DelColLast: 
  1413. //----------------------------------------------------------------------------------------
  1414. #pragma segment GVNonRes
  1415.  
  1416. void TGridView::DelColLast(short numOfCols)
  1417. {
  1418.     DelColAt(fNumOfCols - numOfCols + 1, numOfCols);
  1419. }
  1420.  
  1421. //----------------------------------------------------------------------------------------
  1422. // TGridView::DelRowLast: 
  1423. //----------------------------------------------------------------------------------------
  1424. #pragma segment GVNonRes
  1425.  
  1426. void TGridView::DelRowLast(short numOfRows)
  1427. {
  1428.     DelRowAt(fNumOfRows - numOfRows + 1, numOfRows);
  1429. }
  1430.  
  1431. //----------------------------------------------------------------------------------------
  1432. // TGridView::FirstSelectedCell: 
  1433. //----------------------------------------------------------------------------------------
  1434. #pragma segment GVRes
  1435.  
  1436. GridCell TGridView::FirstSelectedCell()
  1437. {
  1438.     CRect bounds;
  1439.     GridCell aCell;
  1440.     GridCell result;
  1441.  
  1442.     result = gZeroPt;
  1443.     if (IsAnyCellSelected())
  1444.     {
  1445.         bounds = (*fSelections)->rgnBBox;
  1446.         if ((**fSelections).rgnSize == 10)        // whole rectangle 
  1447.             result = bounds[topLeft];
  1448.         else
  1449.             for (short i = bounds.top; i <= bounds.bottom - 1; ++i)
  1450.             {
  1451.                 aCell.v = i;
  1452.                 for (short j = bounds.left; j <= bounds.right - 1; ++j)
  1453.                 {
  1454.                     aCell.h = j;
  1455.                     if (PtInRgn(aCell, fSelections))
  1456.                     {
  1457.                         result = aCell;
  1458.                         return result;
  1459.                     }
  1460.                 }
  1461.             }
  1462.     }
  1463.     return result;
  1464. }
  1465.  
  1466. //----------------------------------------------------------------------------------------
  1467. // TGridView::GetColWidth: 
  1468. //----------------------------------------------------------------------------------------
  1469. #pragma segment GVRes
  1470.  
  1471. short TGridView::GetColWidth(short aCol) const
  1472. {
  1473. #if qRangeCheck && qDebugMsg
  1474.     if ((aCol < 1) || (aCol > fNumOfCols))
  1475.     {
  1476.         fprintf(stderr, "fNumOfCols == &1d  aCol == %1d\n", fNumOfCols, aCol);
  1477.         ProgramBreak("Range Check in GetColWidth");
  1478.     }
  1479. #endif
  1480.  
  1481.     return ((aCol >= 1) && (aCol <= fNumOfCols)) ? fColWidths->GetValue(aCol) : 0;
  1482. }
  1483.  
  1484. //----------------------------------------------------------------------------------------
  1485. // TGridView::GetRowHeight: 
  1486. //----------------------------------------------------------------------------------------
  1487. #pragma segment GVRes
  1488.  
  1489. short TGridView::GetRowHeight(short aRow) const
  1490. {
  1491. #if qRangeCheck && qDebugMsg
  1492.     if ((aRow < 1) || (aRow > fNumOfRows))
  1493.     {
  1494.         fprintf(stderr, "fNumOfRows == &1d  aRow == %1d\n", fNumOfRows, aRow);
  1495.         ProgramBreak("Range Check in GetRowHeight");
  1496.     }
  1497. #endif
  1498.  
  1499.     return ((aRow >= 1) && (aRow <= fNumOfRows)) ? fRowHeights->GetValue(aRow) : 0;
  1500. }
  1501.  
  1502. //----------------------------------------------------------------------------------------
  1503. // TGridView::InvalidateCell: 
  1504. //----------------------------------------------------------------------------------------
  1505. #pragma segment GVRes
  1506.  
  1507. void TGridView::InvalidateCell(GridCell aCell)
  1508. {
  1509.     InvalidateVRect(CellToVRect(aCell));
  1510. }
  1511.  
  1512. //----------------------------------------------------------------------------------------
  1513. // TGridView::InvalidateSelection: 
  1514. //----------------------------------------------------------------------------------------
  1515. #pragma segment GVRes
  1516.  
  1517. void TGridView::InvalidateSelection()
  1518. {
  1519.     if (Focus())
  1520.     {
  1521.         CellsToPixels(fSelections, pInvalidateRgn);
  1522.         InvalidateRegion(pInvalidateRgn);
  1523.     }
  1524. }
  1525.  
  1526. //----------------------------------------------------------------------------------------
  1527. // TGridView::IdentifyPoint: 
  1528. //----------------------------------------------------------------------------------------
  1529. #pragma segment GVRes
  1530.  
  1531. GridViewPart TGridView::IdentifyPoint(const VPoint& thePoint,
  1532.                                       GridCell& aCell)
  1533. {
  1534.     GridViewPart aGridViewPart = badChoice;        // default value
  1535.  
  1536.     aCell = VPointToCell(thePoint);
  1537.  
  1538.     if (aCell != gZeroPt)
  1539.     {
  1540.         VRect aVRect(CellToVRect(aCell));
  1541.         aVRect.Inset(VPoint(fColInset / 2, fRowInset / 2));
  1542.         aGridViewPart = inCell;
  1543.  
  1544.         if (fColInset > 0)
  1545.         {
  1546.             if (thePoint.h < aVRect.left)
  1547.             {
  1548.                 aGridViewPart = inColumn;        // To the left of the cell 
  1549.             }
  1550.             else if (thePoint.h >= aVRect.right)// Remember PtInRgn will report a CPoint
  1551.             // as in a region only if the pixel to the
  1552.             // right and below the CPoint is contained
  1553.             // in the region.
  1554.             {
  1555.                 aGridViewPart = inColumn;        // To the right of the cell 
  1556.                 ++aCell.h;
  1557.                 if (aCell.h > fNumOfCols)
  1558.                     aGridViewPart = badChoice;
  1559.             }
  1560.         }
  1561.  
  1562.         if (fRowInset > 0)
  1563.         {
  1564.             if (thePoint.v < aVRect.top)
  1565.             {
  1566.                 if (aGridViewPart == inColumn)
  1567.                     aGridViewPart = inVertex;    // Click on both 
  1568.                 else
  1569.                     aGridViewPart = inRow;        // Above the cell 
  1570.             }
  1571.             else if (thePoint.v >= aVRect.bottom)// Remember PtInRgn will report a CPoint
  1572.             // as in a region only if the pixel to the
  1573.             // right and below the CPoint is contained
  1574.             // in the region.
  1575.             {
  1576.                 if (aGridViewPart == inColumn)
  1577.                     aGridViewPart = inVertex;    // Click on both 
  1578.                 else
  1579.                     aGridViewPart = inRow;        // Above the cell 
  1580.                 ++aCell.v;
  1581.                 if (aCell.v > fNumOfRows)
  1582.                     aGridViewPart = badChoice;
  1583.             }
  1584.         }
  1585.     }
  1586.     return aGridViewPart;
  1587. }
  1588.  
  1589. //----------------------------------------------------------------------------------------
  1590. // TGridView::InsColBefore: 
  1591. //----------------------------------------------------------------------------------------
  1592. #pragma segment GVRes
  1593.  
  1594. void TGridView::InsColBefore(short aCol,
  1595.                              short numOfCols,
  1596.                              short aWidth)
  1597. {
  1598.     if ((aCol < 1) || (numOfCols < 1))
  1599.     {
  1600.         if (numOfCols != 0)
  1601.         {
  1602. #if qDebugMsg && qRangeCheck
  1603.             fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
  1604.             ProgramBreak("Range Check in InsColBefore");
  1605. #endif
  1606.  
  1607.         }
  1608.     }
  1609.     else
  1610.     {
  1611.         fColWidths->InsertItems(aCol, numOfCols, aWidth);
  1612.         fNumOfCols += numOfCols;
  1613.  
  1614.         AdjustFrame();
  1615.         InvalidateVRect(ColToVRect((short)Max(1, aCol), (short)Max(1, fNumOfCols - aCol + 1)));
  1616.     }
  1617. }
  1618.  
  1619. //----------------------------------------------------------------------------------------
  1620. // TGridView::InsRowBefore: 
  1621. //----------------------------------------------------------------------------------------
  1622. #pragma segment GVRes
  1623.  
  1624. void TGridView::InsRowBefore(short aRow,
  1625.                              short numOfRows,
  1626.                              short aHeight)
  1627. {
  1628.     if ((aRow < 1) || (numOfRows < 1))
  1629.     {
  1630.         if (numOfRows != 0)
  1631.         {
  1632. #if qDebugMsg && qRangeCheck
  1633.             fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
  1634.             ProgramBreak("Range Check in InsRowBefore");
  1635. #endif
  1636.  
  1637.         }
  1638.     }
  1639.     else
  1640.     {
  1641.         fRowHeights->InsertItems(aRow, numOfRows, aHeight);
  1642.         fNumOfRows += numOfRows;
  1643.  
  1644.         AdjustFrame();
  1645.         InvalidateVRect(RowToVRect((short)Max(1, aRow), (short)Max(1, fNumOfRows - aRow + 1)));//!!! Cast
  1646.     }
  1647. }
  1648.  
  1649. //----------------------------------------------------------------------------------------
  1650. // TGridView::InsColLast: 
  1651. //----------------------------------------------------------------------------------------
  1652. #pragma segment GVRes
  1653.  
  1654. void TGridView::InsColLast(short numOfCols,
  1655.                            short aWidth)
  1656. {
  1657.     InsColBefore(fNumOfCols + 1, numOfCols, aWidth);
  1658. }
  1659.  
  1660. //----------------------------------------------------------------------------------------
  1661. // TGridView::InsRowLast: 
  1662. //----------------------------------------------------------------------------------------
  1663. #pragma segment GVRes
  1664.  
  1665. void TGridView::InsRowLast(short numOfRows,
  1666.                            short aHeight)
  1667. {
  1668.     InsRowBefore(fNumOfRows + 1, numOfRows, aHeight);
  1669. }
  1670.  
  1671. //----------------------------------------------------------------------------------------
  1672. // TGridView::InsColFirst: 
  1673. //----------------------------------------------------------------------------------------
  1674. #pragma segment GVRes
  1675.  
  1676. void TGridView::InsColFirst(short numOfCols,
  1677.                             short aWidth)
  1678. {
  1679.     InsColBefore(1, numOfCols, aWidth);
  1680. }
  1681.  
  1682. //----------------------------------------------------------------------------------------
  1683. // TGridView::InsRowFirst: 
  1684. //----------------------------------------------------------------------------------------
  1685. #pragma segment GVRes
  1686.  
  1687. void TGridView::InsRowFirst(short numOfRows,
  1688.                             short aHeight)
  1689. {
  1690.     InsRowBefore(1, numOfRows, aHeight);
  1691. }
  1692.  
  1693. //----------------------------------------------------------------------------------------
  1694. // TGridView::IsCellSelected: 
  1695. //----------------------------------------------------------------------------------------
  1696. #pragma segment GVRes
  1697.  
  1698. Boolean TGridView::IsCellSelected(GridCell aCell)
  1699. {
  1700.     return PtInRgn(aCell, fSelections);
  1701. }
  1702.  
  1703. //----------------------------------------------------------------------------------------
  1704. // TGridView::IsAnyCellSelected: 
  1705. //----------------------------------------------------------------------------------------
  1706. #pragma segment GVRes
  1707.  
  1708. Boolean TGridView::IsAnyCellSelected()
  1709. {
  1710.     return !EmptyRgn(fSelections);
  1711. }
  1712.  
  1713. //----------------------------------------------------------------------------------------
  1714. // TGridView::LastSelectedCell: 
  1715. //----------------------------------------------------------------------------------------
  1716. #pragma segment GVRes
  1717.  
  1718. GridCell TGridView::LastSelectedCell()
  1719. {
  1720.     CRect bounds;
  1721.     GridCell aCell;
  1722.     GridCell result;
  1723.  
  1724.     result = gZeroPt;
  1725.     if (IsAnyCellSelected())
  1726.     {
  1727.         bounds = (**fSelections).rgnBBox;
  1728.         if ((**fSelections).rgnSize == 10)        // whole rectangle 
  1729.         {
  1730.             aCell.h = bounds.right - 1;
  1731.             aCell.v = bounds.bottom - 1;
  1732.             result = aCell;
  1733.         }
  1734.         else
  1735.             for (short i = bounds.bottom - 1; i >= bounds.top; i--)
  1736.             {
  1737.                 aCell.v = i;
  1738.                 for (short j = bounds.right - 1; j >= bounds.left; j--)
  1739.                 {
  1740.                     aCell.h = j;
  1741.                     if (PtInRgn(aCell, fSelections))
  1742.                     {
  1743.                         result = aCell;
  1744.                         return result;
  1745.                     }
  1746.                 }
  1747.             }
  1748.     }
  1749.  
  1750.     return result;
  1751. }
  1752.  
  1753. //----------------------------------------------------------------------------------------
  1754. // TGridView::RowToVRect: 
  1755. //----------------------------------------------------------------------------------------
  1756. #pragma segment GVRes
  1757.  
  1758. VRect TGridView::RowToVRect(short aRow,
  1759.                            short numOfRows) const
  1760. {
  1761.     VRect aRect;
  1762.  
  1763.     if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
  1764.     {
  1765. #if qDebugMsg && qRangeCheck
  1766.         fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
  1767.         ProgramBreak("Range Check in RowToVRect");
  1768. #endif
  1769.  
  1770.         aRect = gZeroVRect;
  1771.     }
  1772.     else                                        // all the params look OK 
  1773.         {
  1774.             long height;
  1775.             long topEdge;
  1776.  
  1777.             if (fRowHeights->fNoOfChunks == 1)    // only one row height 
  1778.             {
  1779.                 height = fRowHeights->GetValue(1);
  1780.                 topEdge = height * (aRow - 1);
  1781.                 height *= numOfRows;
  1782.             }
  1783.             else
  1784.             {
  1785.                 topEdge = fRowHeights->SumValues(1, aRow - 1);
  1786.                 height = fRowHeights->SumValues(aRow, numOfRows);
  1787.             }
  1788.  
  1789.             aRect = VRect(0, topEdge, fColWidths->GetTotal(), topEdge + height);
  1790.         }
  1791.  
  1792.     return aRect;
  1793. }
  1794.  
  1795. //----------------------------------------------------------------------------------------
  1796. // TGridView::ScrollSelectionIntoView: 
  1797. //----------------------------------------------------------------------------------------
  1798. #pragma segment GVRes
  1799.  
  1800. void TGridView::ScrollSelectionIntoView(Boolean redraw)
  1801. {
  1802.  
  1803.     if (IsAnyCellSelected())
  1804.     {
  1805.         CRect rgnBBox = (**fSelections).rgnBBox;
  1806.  
  1807.         VRect topLeftRect(CellToVRect(rgnBBox[topLeft]));
  1808.         VRect botRightRect(CellToVRect(GridCell(rgnBBox.right - 1, rgnBBox.bottom - 1)));
  1809.  
  1810.         VRect selectionRect = topLeftRect | botRightRect;
  1811.  
  1812.         long hCoord = Max(topLeftRect.GetLength(hSel), botRightRect.GetLength(hSel));
  1813.         VPoint minToSee(hCoord, Max(topLeftRect.GetLength(vSel), botRightRect.GetLength(vSel)));
  1814.  
  1815.         RevealRect(selectionRect, minToSee, redraw);
  1816.     }
  1817.     else
  1818.         Inherited::ScrollSelectionIntoView(redraw);
  1819. }
  1820.  
  1821. //----------------------------------------------------------------------------------------
  1822. // TGridView::SetColWidth: 
  1823. //----------------------------------------------------------------------------------------
  1824. #pragma segment GVNonRes
  1825.  
  1826. void TGridView::SetColWidth(short aCol,
  1827.                             short numOfCols,
  1828.                             short aWidth)
  1829. {
  1830. #if qDebugMsg
  1831.     if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
  1832.     {
  1833.         fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
  1834.         ProgramBreak("Range Check in SetColWidth");
  1835.     }
  1836.     else
  1837. #endif
  1838.  
  1839.     if ((fColWidths->fNoOfChunks > 1) || (GetColWidth(1) != aWidth))
  1840.     {
  1841.         long colMax = Max(1, aCol);            // to remove outlined inline warning
  1842.  
  1843.         // invalidate the old screen area of the cols
  1844.         InvalidateVRect(ColToVRect((short)colMax, (short)Max(1, fNumOfCols - aCol + 1)));
  1845.  
  1846.         // set the new col widths and adjust the view's frame
  1847.         fColWidths->DeleteItems(aCol, numOfCols);
  1848.         fColWidths->InsertItems(aCol, numOfCols, aWidth);
  1849.         AdjustFrame();
  1850.  
  1851.         // invalidate the new screen area of the cols
  1852.         InvalidateVRect(ColToVRect((short)colMax, (short)Max(1, fNumOfCols - aCol + 1)));
  1853.     }
  1854. }
  1855.  
  1856. //----------------------------------------------------------------------------------------
  1857. // TGridView::SetRowHeight: 
  1858. //----------------------------------------------------------------------------------------
  1859. #pragma segment GVNonRes
  1860.  
  1861. void TGridView::SetRowHeight(short aRow,
  1862.                              short numOfRows,
  1863.                              short aHeight)
  1864. {
  1865. #if qDebugMsg
  1866.     if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
  1867.     {
  1868.         fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
  1869.         ProgramBreak("Range Check in SetRowHeight.");
  1870.     }
  1871.     else
  1872. #endif
  1873.  
  1874.     if ((fRowHeights->fNoOfChunks != 1) || (GetRowHeight(1) != aHeight))
  1875.     {
  1876.         long rowMax = Max(1, aRow);            // To remove outlined inline warning
  1877.  
  1878.         // invalidate the old screen area of the rows
  1879.         InvalidateVRect(RowToVRect((short)rowMax, (short)Max(1, fNumOfRows - aRow + 1)));
  1880.  
  1881.         // set the new row height and adjust the view's frame
  1882.         fRowHeights->DeleteItems(aRow, numOfRows);
  1883.         fRowHeights->InsertItems(aRow, numOfRows, aHeight);
  1884.         AdjustFrame();
  1885.  
  1886.         // invalidate the new screen area of the rows
  1887.         InvalidateVRect(RowToVRect((short)rowMax, (short)Max(1, fNumOfRows - aRow + 1)));
  1888.     }
  1889. }
  1890.  
  1891. //----------------------------------------------------------------------------------------
  1892. // TGridView::SelectCell: 
  1893. //----------------------------------------------------------------------------------------
  1894. #pragma segment GVRes
  1895.  
  1896. void TGridView::SelectCell(GridCell theCell,
  1897.                            Boolean extendSelection,
  1898.                            Boolean highlight,
  1899.                            Boolean select)
  1900. {
  1901.     SetSelectionRect(CRect(theCell, theCell), extendSelection, highlight, select);
  1902. }
  1903.  
  1904. //----------------------------------------------------------------------------------------
  1905. // TGridView::SetEmptySelection: 
  1906. //----------------------------------------------------------------------------------------
  1907. #pragma segment GVRes
  1908.  
  1909. void TGridView::SetEmptySelection(Boolean highlight)
  1910. {
  1911.     SetEmptyRgn(fTemporarySelections);
  1912.     SetSelection(fTemporarySelections, kDontExtend, highlight, kSelect);
  1913. }
  1914.  
  1915. //----------------------------------------------------------------------------------------
  1916. // TGridView::SetSelection: 
  1917. //----------------------------------------------------------------------------------------
  1918. #pragma segment GVRes
  1919.  
  1920. void TGridView::SetSelection(RgnHandle cellsToSelect,
  1921.                              Boolean extendSelection,
  1922.                              Boolean highlight,
  1923.                              Boolean select)
  1924. {
  1925. #if qDebug
  1926.     CRect bounds = (**cellsToSelect).rgnBBox;
  1927.  
  1928.     if (fSingleSelection && ((bounds.GetLength(hSel) > 1) || (bounds.GetLength(vSel) > 1)))
  1929.         ProgramBreak("Attempt to select multiple cells when fSingleSelection is true");
  1930.     if (!EmptyRgn(cellsToSelect))
  1931.         if ((bounds.left < 1) || (bounds.top < 1) || (bounds.right > fNumOfCols + 1) || (bounds.bottom > fNumOfRows + 1))
  1932.             ProgramBreak("Attempted selection is outside the range of cells");
  1933. #endif
  1934.  
  1935.     if (highlight)
  1936.         CopyRgn(fSelections, pPreviousSelection);// save the old selection 
  1937.  
  1938.     CTemporaryRegion tempRgn;
  1939.  
  1940.     SetRectRgn(tempRgn, 1, 1, fNumOfCols + 1, fNumOfRows + 1);
  1941.     SectRgn(cellsToSelect, tempRgn, tempRgn);
  1942.  
  1943.     if (extendSelection && select)                // extend the selection region 
  1944.         UnionRgn(tempRgn, fSelections, fSelections);
  1945.     else if (select)                            // reset the selection region 
  1946.         CopyRgn(tempRgn, fSelections);
  1947.     else                                        // need to de-select the new region 
  1948.         DiffRgn(fSelections, tempRgn, fSelections);
  1949.  
  1950.     UserSelectionChanged(this);                    // so doc updates its designator 
  1951.  
  1952.     CopyRgn(fSelections, fHLRegion);
  1953.  
  1954.     if (highlight)
  1955.     {
  1956.         HLState currentHL = GetCurrentHL();
  1957.  
  1958.         // Turn the deselected cells off 
  1959.         DiffRgn(pPreviousSelection, fSelections, pDifference);
  1960.         HighlightCells(pDifference, currentHL, hlOff);
  1961.  
  1962.         // Turn the newly selected cells on 
  1963.         DiffRgn(fSelections, pPreviousSelection, pDifference);
  1964.         HighlightCells(pDifference, hlOff, currentHL);
  1965.     }
  1966.  
  1967. #if qDrag
  1968.     if (GetDraggable())
  1969.         gDispatcher->InvalidateMouseRegions();
  1970. #endif
  1971.  
  1972. }
  1973.  
  1974. //----------------------------------------------------------------------------------------
  1975. // TGridView::SetSelectionRect: 
  1976. //----------------------------------------------------------------------------------------
  1977. #pragma segment GVRes
  1978.  
  1979. void TGridView::SetSelectionRect(const CRect& selectionRect,
  1980.                                  Boolean extendSelection,
  1981.                                  Boolean highlight,
  1982.                                  Boolean select)
  1983.  
  1984. {
  1985.     if (selectionRect == gZeroRect)
  1986.         SetEmptyRgn(fTemporarySelections);
  1987.     else
  1988.         SetRectRgn(fTemporarySelections, selectionRect.left, selectionRect.top, selectionRect.right + 1, selectionRect.bottom + 1);
  1989.  
  1990.     SetSelection(fTemporarySelections, extendSelection, highlight, select);
  1991. }
  1992.  
  1993. //----------------------------------------------------------------------------------------
  1994. // TGridView::SetSingleSelection: 
  1995. //----------------------------------------------------------------------------------------
  1996. #pragma segment GVNonRes
  1997.  
  1998. void TGridView::SetSingleSelection(Boolean theSetting)
  1999. {
  2000.     fSingleSelection = theSetting;
  2001. }
  2002.  
  2003. //----------------------------------------------------------------------------------------
  2004. // TGridView::VPointToCell: 
  2005. //----------------------------------------------------------------------------------------
  2006. #pragma segment GVRes
  2007.  
  2008. GridCell TGridView::VPointToCell(const VPoint& aPoint) const
  2009. {
  2010.     GridCell aCell(fColWidths->FindItem(aPoint.h), fRowHeights->FindItem(aPoint.v));
  2011.  
  2012.     return ((aCell.h == 0) || (aCell.v == 0)) ? gZeroPt : aCell;
  2013. }
  2014.  
  2015. //----------------------------------------------------------------------------------------
  2016. // TGridView::VPointToLastCell: 
  2017. //----------------------------------------------------------------------------------------
  2018. #pragma segment GVRes
  2019.  
  2020. GridCell TGridView::VPointToLastCell(const VPoint& aPoint) const
  2021. {
  2022.     GridCell aCell;
  2023.  
  2024.     aCell.h = fColWidths->FindItem(aPoint.h);
  2025.     if (aCell.h == 0)                            // If its invalid, return the last column 
  2026.         aCell.h = fNumOfCols;
  2027.  
  2028.     aCell.v = fRowHeights->FindItem(aPoint.v);
  2029.     if (aCell.v == 0)                            // If its invalid, return the last row 
  2030.         aCell.v = fNumOfRows;
  2031.  
  2032.     return aCell;
  2033. }
  2034.  
  2035. #if qDrag
  2036.  
  2037. //----------------------------------------------------------------------------------------
  2038. // TGridView::DoMakeDragCursorRegion: 
  2039. //----------------------------------------------------------------------------------------
  2040. #pragma segment MADragRes
  2041.  
  2042. RgnHandle TGridView::DoMakeDragCursorRegion()
  2043. {
  2044.     RgnHandle dragCursorRegion = NULL;
  2045.  
  2046.     if (IsAnyCellSelected())
  2047.     {
  2048.         CTemporaryRegion drawableRgn;
  2049.         CTemporaryRegion cellRegion;
  2050.  
  2051.         dragCursorRegion = MakeNewRgn();
  2052.  
  2053.         CSelectedCellIterator iter(this);
  2054.  
  2055.         for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
  2056.         {
  2057.             RectRgn(cellRegion, &ViewToQDRect(CellToVRect(aCell)));
  2058.             UnionRgn(cellRegion, dragCursorRegion, dragCursorRegion);
  2059.         }
  2060.  
  2061.         GetDrawableRegion(drawableRgn);            // return the interesection of the selection
  2062.         SectRgn(dragCursorRegion, drawableRgn, dragCursorRegion);// and the view's drawable region
  2063.     }
  2064.  
  2065.     return dragCursorRegion;
  2066. }
  2067.  
  2068. //----------------------------------------------------------------------------------------
  2069. // TGridView::WillDrag: 
  2070. //----------------------------------------------------------------------------------------
  2071. #pragma segment MADragRes
  2072.  
  2073. Boolean TGridView::WillDrag(const VPoint& localMouse,
  2074.                             const RgnHandle dragCursorRegion)
  2075. {
  2076.     Boolean willDrag = (!IsShiftKeyDown() && !IsCommandKeyDown() && Inherited::WillDrag(localMouse, dragCursorRegion));
  2077.  
  2078.     return willDrag;
  2079. }
  2080.  
  2081. //----------------------------------------------------------------------------------------
  2082. // TGridView::DoDragEnter: 
  2083. //----------------------------------------------------------------------------------------
  2084. #pragma segment MADragNonRes
  2085.  
  2086. void TGridView::DoDragEnter()
  2087. {
  2088.     fLastTargetCell = gZeroPt;
  2089.     fLastCaretTime = 0L;
  2090.     fCaretIsShown = FALSE;
  2091. }
  2092.  
  2093. //----------------------------------------------------------------------------------------
  2094. // TGridView::DoDragWithin: 
  2095. //----------------------------------------------------------------------------------------
  2096. #pragma segment MADragNonRes
  2097.  
  2098. void TGridView::DoDragWithin(const VPoint& localMouse)
  2099. {
  2100.     GridCell targetCell;
  2101.     Boolean targetChanged;
  2102.     unsigned long currentTime = TickCount();
  2103.  
  2104.     targetCell = VPointToLastCell(localMouse);
  2105.     targetChanged = (fLastTargetCell != targetCell);
  2106.  
  2107.     if (targetChanged && fCaretIsShown)
  2108.         DrawCellCaret(fLastTargetCell);
  2109.  
  2110.     if (targetChanged || (currentTime - fLastCaretTime) > GetCaretTime())
  2111.     {
  2112.         DrawCellCaret(targetCell);
  2113.         fLastTargetCell = targetCell;
  2114.         fLastCaretTime = currentTime;
  2115.     }
  2116. }
  2117.  
  2118. //----------------------------------------------------------------------------------------
  2119. // TGridView::DoDragLeave: 
  2120. //----------------------------------------------------------------------------------------
  2121. #pragma segment MADragNonRes
  2122.  
  2123. void TGridView::DoDragLeave()
  2124. {
  2125.     if (fCaretIsShown)
  2126.         DrawCellCaret(fLastTargetCell);
  2127. }
  2128.  
  2129. //----------------------------------------------------------------------------------------
  2130. // TGridView::DrawCellCaret: 
  2131. //----------------------------------------------------------------------------------------
  2132. #pragma segment MADragNonRes
  2133.  
  2134. void TGridView::DrawCellCaret(GridCell targetCell)
  2135. {
  2136.     // don't allow a cell in the current selection to be targeted
  2137.     if (CanSelectCell(targetCell) && !((TDragDropSession::fgDragDropSession->GetCurrentDragSource() == this) && IsCellSelected(targetCell)))
  2138.     {
  2139.         PenNormal();
  2140.         PenPat(&qd.gray);
  2141.         PenMode(notPatXor);
  2142.         PenSize(2, 2);
  2143.  
  2144.         FrameRect(&ViewToQDRect((targetCell == gZeroPt) ? GetDrawableRect() : CellToVRect(targetCell)));
  2145.  
  2146.         PenNormal();
  2147.     }
  2148.  
  2149.     fCaretIsShown = !fCaretIsShown;
  2150. }
  2151.  
  2152. #endif // qDrag
  2153.  
  2154. //========================================================================================
  2155. // CLASS TTextGridView
  2156. //========================================================================================
  2157. #undef Inherited
  2158. #define Inherited TGridView
  2159.  
  2160. #pragma segment GVOpen
  2161. MA_DEFINE_CLASS_M1(TTextGridView,
  2162.                    Inherited);
  2163.  
  2164. //----------------------------------------------------------------------------------------
  2165. // TTextGridView constructor
  2166. //----------------------------------------------------------------------------------------
  2167. #pragma segment GVOpen
  2168.  
  2169. TTextGridView::TTextGridView()
  2170. {
  2171.     fTextStyle = gSystemStyle;
  2172.     fTextStyleRsrcID = kNoResource;
  2173.     fJustification = teFlushDefault;
  2174.     fPreferOutline = kDontPreferOutline;
  2175.     fLineHeight = 0;
  2176.     fLineAscent = 0;
  2177. }
  2178.  
  2179. //----------------------------------------------------------------------------------------
  2180. // TTextGridView destructor
  2181. //----------------------------------------------------------------------------------------
  2182. #pragma segment MADestructorRes
  2183.  
  2184. TTextGridView::~TTextGridView()
  2185. {
  2186. }
  2187.  
  2188. //----------------------------------------------------------------------------------------
  2189. // TTextGridView::ITextGridView: 
  2190. //----------------------------------------------------------------------------------------
  2191. #pragma segment GVOpen
  2192.  
  2193. void TTextGridView::ITextGridView(TDocument* itsDocument,
  2194.                                   // Its document 
  2195.                                   TView* itsSuperView,
  2196.                                   // Its parent view 
  2197.                                   const VPoint& itsLocation,
  2198.                                   // Top, Left in parent's coords 
  2199.                                   const VPoint& itsSize,
  2200.                                   SizeDeterminer itsHSizeDet,
  2201.                                   SizeDeterminer itsVSizeDet,
  2202.                                   // Size determiners 
  2203.                                   short numOfRows,
  2204.                                   // Number of rows initially 
  2205.                                   short numOfCols,
  2206.                                   // Number of columns initially 
  2207.                                   short rowHeight,
  2208.                                   // Row height, or zero for font height 
  2209.                                   short colWidth,
  2210.                                   // Width of items in the columns 
  2211.                                   Boolean adornRows,
  2212.                                   // Adornment for Rows? 
  2213.                                   Boolean adornCols,
  2214.                                   // Adornment for Columns? 
  2215.                                   short rowInset,
  2216.                                   // horizontal space between cells 
  2217.                                   short colInset,
  2218.                                   // vertical space between cells 
  2219.                                   Boolean singleSelection,
  2220.                                   // single cell selection? 
  2221.                                   const TextStyle& itsTextStyle)// size, color, etc. font info 
  2222.  
  2223. {
  2224.     if (rowHeight == 0)
  2225.     {
  2226.         // Compute the rowHeight for call to IGridView based on the line height and the row inset.
  2227.         GrafPtr savedPort;
  2228.         GetPort(&savedPort);                    // save the port
  2229.         SetPortWindowPort(gWorkPort);            // set port to the work port
  2230.  
  2231.         SetPortTextStyle(itsTextStyle);            // set the port's text style
  2232.         PenNormal();
  2233.  
  2234.         FontInfo theFontInfo;
  2235.         rowHeight = MAGetFontInfo(theFontInfo) + rowInset;
  2236.  
  2237.         SetPort(savedPort);                        // restore port
  2238.     }
  2239.  
  2240.     IGridView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, numOfRows, numOfCols, rowHeight, colWidth, adornRows, adornCols, rowInset, colInset, singleSelection);
  2241.  
  2242.     fTextStyle = itsTextStyle;
  2243.  
  2244.     SetUpFont();
  2245.  
  2246.     if ((fNumOfCols == 1) && (fSizeDeterminer[hSel] != sizeFixed) && (GetColWidth(1) == 0) && fSuperView)
  2247.         SetColWidth(1, fNumOfCols, (short)fSuperView->fSize.h);//!!! Note cast
  2248. }
  2249.  
  2250. //----------------------------------------------------------------------------------------
  2251. // TTextGridView::GetStandardSignature: 
  2252. //----------------------------------------------------------------------------------------
  2253. #pragma segment GVWriteResource
  2254.  
  2255. IDType TTextGridView::GetStandardSignature()    // override 
  2256. {
  2257.     return kStdTextGridView;
  2258. }
  2259.  
  2260. //----------------------------------------------------------------------------------------
  2261. // TTextGridView::ReadFields: 
  2262. //----------------------------------------------------------------------------------------
  2263. #pragma segment GVReadResource
  2264.  
  2265. void TTextGridView::ReadFields(TStream* aStream)// override 
  2266. {
  2267.     Inherited::ReadFields(aStream);
  2268.  
  2269.     FailInfo fi;
  2270.     Try(fi)
  2271.     {
  2272.         fTextStyleRsrcID = aStream->ReadInteger();
  2273.         if (fTextStyleRsrcID != kNoResource)
  2274.         {
  2275.             TextStyle itsTextStyle;
  2276.             MAGetTextStyle(fTextStyleRsrcID, itsTextStyle);
  2277.             fTextStyle = itsTextStyle;
  2278.         }
  2279.  
  2280.         fPreferOutline = aStream->ReadBoolean();
  2281.         fi.Success();
  2282.     }
  2283.     else                                        // Recover
  2284.     {
  2285.         Free();
  2286.         fi.ReSignal();
  2287.     }
  2288.  
  2289.     SetUpFont();
  2290.  
  2291.     if (fNumOfRows > 0)
  2292.         if (GetRowHeight(1) == 0)                // set row height from font 
  2293.             SetRowHeight(1, fNumOfRows, fLineHeight + fRowInset);
  2294.  
  2295.     if ((fNumOfCols == 1) && (fSizeDeterminer[hSel] != sizeFixed) && (GetColWidth(1) == 0))
  2296.         SetColWidth(1, fNumOfCols, (short)fSize.h);//!!! Note cast
  2297. }
  2298.  
  2299. //----------------------------------------------------------------------------------------
  2300. // TTextGridView::WriteFields: 
  2301. //----------------------------------------------------------------------------------------
  2302. #pragma segment GVWriteResource
  2303.  
  2304. void TTextGridView::WriteFields(TStream* aStream)// override 
  2305. {
  2306.     Inherited::WriteFields(aStream);
  2307.  
  2308.     aStream->WriteInteger(fTextStyleRsrcID);
  2309.     aStream->WriteBoolean(fPreferOutline);
  2310. }
  2311.  
  2312. //----------------------------------------------------------------------------------------
  2313. // TTextGridView::DrawCell: 
  2314. //----------------------------------------------------------------------------------------
  2315. #pragma segment GVRes
  2316.  
  2317. void TTextGridView::DrawCell(GridCell aCell,
  2318.                              const VRect& aRect)// override 
  2319. {
  2320.     CStr255 theText;
  2321.     GetText(aCell, theText);
  2322.  
  2323.     if (GetColWidth(aCell.h) > 0)
  2324.     {
  2325.         CRect r(ViewToQDRect(aRect));
  2326.  
  2327.         if (CanSelectCell(aCell))
  2328.             MADrawString(theText, r, fJustification, fPreferOutline);
  2329.         else
  2330.         {
  2331.             GrafPtr currentPort;
  2332.             GetPort(¤tPort);
  2333.  
  2334.             PenState pState;
  2335.             GetPenState(&pState);                // save pen state
  2336.             short txMode = currentPort->txMode;
  2337.  
  2338.             if (qNeedsColorQD || HasColorQD())
  2339.                 TextMode(grayishTextOr);
  2340.  
  2341.             MADrawString(theText, r, fJustification, fPreferOutline);
  2342.  
  2343.             if (!(qNeedsColorQD || HasColorQD()))
  2344.             {
  2345.                 PenPat(&qd.gray);
  2346.                 PenMode(patBic);
  2347.                 PaintRect(&r);
  2348.             }
  2349.  
  2350.             SetPenState(&pState);                // restore pen state
  2351.             TextMode(txMode);
  2352.         }
  2353.     }
  2354. }
  2355.  
  2356. //----------------------------------------------------------------------------------------
  2357. // TTextGridView::Focus: 
  2358. //----------------------------------------------------------------------------------------
  2359. #pragma segment GVRes
  2360.  
  2361. Boolean TTextGridView::Focus()                    // override 
  2362. {
  2363.     if (Inherited::Focus())
  2364.     {
  2365.         SetPen();
  2366.         return TRUE;
  2367.     }
  2368.     else
  2369.         return FALSE;
  2370. }
  2371.  
  2372. //----------------------------------------------------------------------------------------
  2373. // TTextGridView::SetUpFont: 
  2374. //----------------------------------------------------------------------------------------
  2375. #pragma segment GVOpen
  2376.  
  2377. void TTextGridView::SetUpFont()
  2378. {
  2379.     GrafPtr savedPort;
  2380.  
  2381.     // set port to the work port
  2382.     GetPort(&savedPort);
  2383.     SetPortWindowPort(gWorkPort);
  2384.  
  2385.     {                                            // block for CWhileOutlinePreferred (which has a constructor/destructor)
  2386.         CWhileOutlinePreferred setOP(fPreferOutline);
  2387.         FontInfo theFontInfo;
  2388.  
  2389.         SetPen();
  2390.         fLineHeight = MAGetFontInfo(theFontInfo);// returns height of font 
  2391.         fLineAscent = theFontInfo.ascent + (theFontInfo.leading / 2);
  2392.     }
  2393.  
  2394.     // restore port
  2395.     SetPort(savedPort);
  2396. }
  2397.  
  2398. //----------------------------------------------------------------------------------------
  2399. // TTextGridView::SetPen: 
  2400. //----------------------------------------------------------------------------------------
  2401. #pragma segment GVRes
  2402.  
  2403. void TTextGridView::SetPen()
  2404. {
  2405.     TextStyle itsTextStyle = fTextStyle;
  2406.     SetPortTextStyle(itsTextStyle);
  2407.     PenNormal();
  2408. }
  2409.  
  2410. //----------------------------------------------------------------------------------------
  2411. // TTextGridView::GetText: 
  2412. //----------------------------------------------------------------------------------------
  2413. #pragma segment GVRes
  2414.  
  2415. void TTextGridView::GetText(GridCell            /* aCell */,
  2416.                             CStr255& aString)
  2417. {
  2418.     aString.Empty();
  2419. }
  2420.  
  2421. #if qDrag
  2422.  
  2423. //----------------------------------------------------------------------------------------
  2424. // TTextGridView::DoAddDragContent: 
  2425. //----------------------------------------------------------------------------------------
  2426. #pragma segment MADragNonRes
  2427.  
  2428. void TTextGridView::DoAddDragContent()
  2429. {
  2430.     CFlavorFlags flags;
  2431.     TDragItem * dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
  2432.  
  2433.     dragItem->PromiseFlavor('TEXT', flags);
  2434. }
  2435.  
  2436. //----------------------------------------------------------------------------------------
  2437. // TTextGridView::DoFulfillPromise: 
  2438. //----------------------------------------------------------------------------------------
  2439. #pragma segment MADragNonRes
  2440.  
  2441. void TTextGridView::DoFulfillPromise(TDragItem* promisedItem)
  2442. {
  2443.     switch (promisedItem->GetFlavorType())
  2444.     {
  2445.         case 'TEXT':
  2446.             {
  2447.                 CSelectedCellIterator iter(this);
  2448.                 GridCell lastCell = gZeroPt;
  2449.                 TStream * flavorStream = promisedItem->GetDataStream();
  2450.                 CStr255 text;
  2451.  
  2452.                 for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
  2453.                 {
  2454.                     GetText(aCell, text);
  2455.                     flavorStream->WriteBytes(&text[1], text.Length());
  2456.  
  2457.                     if (aCell.v > lastCell.v)
  2458.                         flavorStream->WriteCharacter('\n');
  2459.                     else
  2460.                         flavorStream->WriteCharacter('\t');
  2461.                     lastCell = aCell;
  2462.                 }
  2463.                 FreeIfObject(flavorStream);
  2464.             }
  2465.             break;
  2466.  
  2467.         default:
  2468.             Inherited::DoFulfillPromise(promisedItem);
  2469.             break;
  2470.     }
  2471. }
  2472.  
  2473. #endif // qDrag
  2474.  
  2475. //========================================================================================
  2476. // CLASS TTextListView
  2477. //========================================================================================
  2478. #undef Inherited
  2479. #define Inherited TTextGridView
  2480.  
  2481. #pragma segment GVOpen
  2482. MA_DEFINE_CLASS_M1(TTextListView,
  2483.                    Inherited);
  2484.  
  2485. //----------------------------------------------------------------------------------------
  2486. // TTextListView::TTextListView: Empty constructor to satisfy the compiler.
  2487. //----------------------------------------------------------------------------------------
  2488. #pragma segment GVOpen
  2489.  
  2490. TTextListView::TTextListView()
  2491. {
  2492. }
  2493.  
  2494. //----------------------------------------------------------------------------------------
  2495. // TTextListView destructor
  2496. //----------------------------------------------------------------------------------------
  2497. #pragma segment MADestructorRes
  2498.  
  2499. TTextListView::~TTextListView()
  2500. {
  2501. }
  2502.  
  2503. //----------------------------------------------------------------------------------------
  2504. // TTextListView::ITextListView: 
  2505. //----------------------------------------------------------------------------------------
  2506. #pragma segment GVOpen
  2507.  
  2508. void TTextListView::ITextListView(TDocument* itsDocument,
  2509.                                   // Its document 
  2510.                                   TView* itsSuperView,
  2511.                                   // Its parent view 
  2512.                                   const VPoint& itsLocation,
  2513.                                   // Top, Left in parent's coords 
  2514.                                   const VPoint& itsSize,
  2515.                                   SizeDeterminer itsHSizeDet,
  2516.                                   SizeDeterminer itsVSizeDet,
  2517.                                   // Size determiners 
  2518.                                   short numOfItems,
  2519.                                   // Number of items initially 
  2520.                                   short rowHeight,
  2521.                                   // Row height, or zero for font height 
  2522.                                   short colWidth,
  2523.                                   // Width of items in the columns 
  2524.                                   Boolean adornRows,
  2525.                                   // Draw the row adornments? 
  2526.                                   Boolean adornCols,
  2527.                                   // Draw the col adornment? 
  2528.                                   short rowInset,
  2529.                                   // Amount to inset the rows 
  2530.                                   short colInset,
  2531.                                   // Amount to inset the column 
  2532.                                   Boolean singleSelection,
  2533.                                   // single cell selection? 
  2534.                                   const TextStyle& itsTextStyle)// size, color, etc. font info 
  2535.  
  2536. {
  2537.     ITextGridView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, numOfItems, 1, rowHeight, colWidth, adornRows, adornCols, rowInset, colInset, singleSelection, itsTextStyle);
  2538. }
  2539.  
  2540. //----------------------------------------------------------------------------------------
  2541. // TTextListView::GetStandardSignature: 
  2542. //----------------------------------------------------------------------------------------
  2543. #pragma segment GVWriteResource
  2544.  
  2545. IDType TTextListView::GetStandardSignature()    // override 
  2546. {
  2547.     return kStdTextListView;
  2548. }
  2549.  
  2550. //----------------------------------------------------------------------------------------
  2551. // TTextListView::CanSelectCell: 
  2552. //----------------------------------------------------------------------------------------
  2553. #pragma segment GVRes
  2554.  
  2555. Boolean TTextListView::CanSelectCell(GridCell aCell)// override 
  2556. {
  2557.     return (Inherited::CanSelectCell(aCell) && CanSelectItem(aCell.v));
  2558. }
  2559.  
  2560. //----------------------------------------------------------------------------------------
  2561. // TTextListView::CanSelectItem: 
  2562. //----------------------------------------------------------------------------------------
  2563. #pragma segment GVRes
  2564.  
  2565. Boolean TTextListView::CanSelectItem(short anItem)
  2566. {
  2567.     return ((anItem >= 1) && (anItem <= fNumOfRows));
  2568. }
  2569.  
  2570. //----------------------------------------------------------------------------------------
  2571. // TTextListView::DelItemAt: 
  2572. //----------------------------------------------------------------------------------------
  2573. #pragma segment GVNonRes
  2574.  
  2575. void TTextListView::DelItemAt(short anItem,
  2576.                               short numOfItems)
  2577. {
  2578.     DelRowAt(anItem, numOfItems);
  2579. }
  2580.  
  2581. //----------------------------------------------------------------------------------------
  2582. // TTextListView::DelItemFirst: 
  2583. //----------------------------------------------------------------------------------------
  2584. #pragma segment GVNonRes
  2585.  
  2586. void TTextListView::DelItemFirst(short numOfItems)
  2587. {
  2588.     DelItemAt(1, numOfItems);
  2589. }
  2590.  
  2591. //----------------------------------------------------------------------------------------
  2592. // TTextListView::DelItemLast: 
  2593. //----------------------------------------------------------------------------------------
  2594. #pragma segment GVNonRes
  2595.  
  2596. void TTextListView::DelItemLast(short numOfItems)
  2597. {
  2598.     DelItemAt(fNumOfRows - numOfItems + 1, numOfItems);
  2599. }
  2600.  
  2601. //----------------------------------------------------------------------------------------
  2602. // TTextListView::DoKeySelection: 
  2603. //----------------------------------------------------------------------------------------
  2604. #pragma segment GVRes
  2605.  
  2606. void TTextListView::DoKeySelection(const CStr255& selectionString)
  2607. {
  2608.     short lastItemIndex = GetItemIndexOrdered(1);
  2609.     CStr255 upperCaseSelectionString(selectionString);
  2610.     UprStr255(upperCaseSelectionString);
  2611.  
  2612.     for (short i = 1; i <= fNumOfRows; i++)
  2613.     {
  2614.         short itemIndex = GetItemIndexOrdered(i);
  2615.  
  2616.         CStr255 itemText;
  2617.         GetItemText(itemIndex, itemText);
  2618.         UprStr255(itemText);
  2619.  
  2620.         itemText.Delete(upperCaseSelectionString.Length() + 1, itemText.Length() - upperCaseSelectionString.Length());
  2621.         
  2622.         short compareResult = CPascalStr::CPascalStrCompare(itemText, upperCaseSelectionString);
  2623.         if (compareResult > 0)
  2624.             break;                // the previous index is the closest match
  2625.  
  2626.         lastItemIndex = itemIndex;
  2627.  
  2628.         if (compareResult == 0)
  2629.             break;                // the current index is the closest match
  2630.     }
  2631.  
  2632.     SelectItem(lastItemIndex, FALSE, TRUE, TRUE);
  2633.     ScrollSelectionIntoView(TRUE);
  2634. }
  2635.  
  2636. //----------------------------------------------------------------------------------------
  2637. // TTextListView::FirstSelectedItem: 
  2638. //----------------------------------------------------------------------------------------
  2639. #pragma segment GVRes
  2640.  
  2641. short TTextListView::FirstSelectedItem()
  2642. {
  2643.     return FirstSelectedCell().v;
  2644. }
  2645.  
  2646. //----------------------------------------------------------------------------------------
  2647. // TTextListView::GetItemHeight: 
  2648. //----------------------------------------------------------------------------------------
  2649. #pragma segment GVRes
  2650.  
  2651. short TTextListView::GetItemHeight(short anItem)
  2652. {
  2653.     return GetRowHeight(anItem);
  2654. }
  2655.  
  2656. //----------------------------------------------------------------------------------------
  2657. // TTextListView::GetItemWidth: 
  2658. //----------------------------------------------------------------------------------------
  2659. #pragma segment GVRes
  2660.  
  2661. short TTextListView::GetItemWidth()
  2662. {
  2663.     return GetColWidth(1);
  2664. }
  2665.  
  2666. //----------------------------------------------------------------------------------------
  2667. // TTextListView::GetItemText: 
  2668. //----------------------------------------------------------------------------------------
  2669. #pragma segment GVRes
  2670.  
  2671. void TTextListView::GetItemText(short,
  2672.                                 CStr255& aString)
  2673. {
  2674.     aString.Empty();
  2675. }
  2676.  
  2677. //----------------------------------------------------------------------------------------
  2678. // TTextListView::GetItemIndexOrdered: 
  2679. //----------------------------------------------------------------------------------------
  2680. #pragma segment GVRes
  2681.  
  2682. short TTextListView::GetItemIndexOrdered(short nthItem)
  2683. {
  2684.     return nthItem;
  2685. }
  2686.  
  2687. //----------------------------------------------------------------------------------------
  2688. // TTextListView::GetText: 
  2689. //----------------------------------------------------------------------------------------
  2690. #pragma segment GVRes
  2691.  
  2692. void TTextListView::GetText(GridCell aCell,
  2693.                             CStr255& aString)    // override 
  2694. {
  2695.     GetItemText(aCell.v, aString);
  2696. }
  2697.  
  2698. //----------------------------------------------------------------------------------------
  2699. // TTextListView::InsItemBefore: 
  2700. //----------------------------------------------------------------------------------------
  2701. #pragma segment GVRes
  2702.  
  2703. void TTextListView::InsItemBefore(short anItem,
  2704.                                   short numOfItems)
  2705. {
  2706.     InsRowBefore(anItem, numOfItems, fLineHeight + fRowInset);
  2707. }
  2708.  
  2709. //----------------------------------------------------------------------------------------
  2710. // TTextListView::InsItemFirst: 
  2711. //----------------------------------------------------------------------------------------
  2712. #pragma segment GVRes
  2713.  
  2714. void TTextListView::InsItemFirst(short numOfItems)
  2715. {
  2716.     InsItemBefore(1, numOfItems);
  2717. }
  2718.  
  2719. //----------------------------------------------------------------------------------------
  2720. // TTextListView::InsItemLast: 
  2721. //----------------------------------------------------------------------------------------
  2722. #pragma segment GVRes
  2723.  
  2724. void TTextListView::InsItemLast(short numOfItems)
  2725. {
  2726.     InsItemBefore(fNumOfRows + 1, numOfItems);
  2727. }
  2728.  
  2729. //----------------------------------------------------------------------------------------
  2730. // TTextListView::InvalidateItem: 
  2731. //----------------------------------------------------------------------------------------
  2732. #pragma segment GVRes
  2733.  
  2734. void TTextListView::InvalidateItem(short anItem)
  2735. {
  2736.     InvalidateCell(GridCell(1, anItem));
  2737. }
  2738.  
  2739. //----------------------------------------------------------------------------------------
  2740. // TTextListView::IsItemSelected: 
  2741. //----------------------------------------------------------------------------------------
  2742. #pragma segment GVRes
  2743.  
  2744. Boolean TTextListView::IsItemSelected(short anItem)
  2745. {
  2746.     return IsCellSelected(GridCell(1, anItem));
  2747. }
  2748.  
  2749. //----------------------------------------------------------------------------------------
  2750. // TTextListView::LastSelectedItem: 
  2751. //----------------------------------------------------------------------------------------
  2752. #pragma segment GVRes
  2753.  
  2754. short TTextListView::LastSelectedItem()
  2755. {
  2756.     return LastSelectedCell().v;
  2757. }
  2758.  
  2759. //----------------------------------------------------------------------------------------
  2760. // TTextListView::SetFrame: 
  2761. //----------------------------------------------------------------------------------------
  2762. #pragma segment GVNonRes
  2763.  
  2764. void TTextListView::SetFrame(const VRect& newFrame,
  2765.                              Boolean invalidate)// override 
  2766. {
  2767.     VPoint oldSize(fSize);
  2768.  
  2769.     Inherited::SetFrame(newFrame, invalidate);
  2770.  
  2771.     if (fNumOfCols == 1 && fSize != oldSize)
  2772.     {
  2773.         fColWidths->SetTotal(fColWidths->GetTotal() + fSize.h - fColWidths->ChunkAt(0).value);
  2774.         fColWidths->ChunkAt(0).value = (short)fSize.h;//!!! Note cast
  2775.     }
  2776. }
  2777.  
  2778. //----------------------------------------------------------------------------------------
  2779. // TTextListView::SelectCell: 
  2780. //----------------------------------------------------------------------------------------
  2781. #pragma segment GVRes
  2782.  
  2783. void TTextListView::SelectCell(GridCell theCell,
  2784.                                Boolean extendSelection,
  2785.                                Boolean highlight,
  2786.                                Boolean select)    // override 
  2787. {
  2788.     SelectItem(theCell.v, extendSelection, highlight, select);
  2789. }
  2790.  
  2791. //----------------------------------------------------------------------------------------
  2792. // TTextListView::SelectItem: 
  2793. //----------------------------------------------------------------------------------------
  2794. #pragma segment GVRes
  2795.  
  2796. void TTextListView::SelectItem(short anItem,
  2797.                                Boolean extendSelection,
  2798.                                Boolean highlight,
  2799.                                Boolean select)
  2800. {
  2801.     Inherited::SelectCell(GridCell((short)Min(1, anItem), anItem), extendSelection, highlight, select);
  2802. }
  2803.  
  2804. //----------------------------------------------------------------------------------------
  2805. // TTextListView::SetItemHeight: 
  2806. //----------------------------------------------------------------------------------------
  2807. #pragma segment GVNonRes
  2808.  
  2809. void TTextListView::SetItemHeight(short anItem,
  2810.                                   short numOfItems,
  2811.                                   short aHeight)
  2812. {
  2813.     SetRowHeight(anItem, numOfItems, aHeight);
  2814. }
  2815.  
  2816. //----------------------------------------------------------------------------------------
  2817. // TTextListView::SetItemWidth: 
  2818. //----------------------------------------------------------------------------------------
  2819. #pragma segment GVNonRes
  2820.  
  2821. void TTextListView::SetItemWidth(short aWidth)
  2822. {
  2823.     SetColWidth(1, 1, aWidth);
  2824. }
  2825.  
  2826.  
  2827. //========================================================================================
  2828. // CLASS TCellSelectCommand
  2829. //========================================================================================
  2830. #undef Inherited
  2831. #define Inherited TTracker
  2832.  
  2833. #pragma segment GVSelCommand
  2834. MA_DEFINE_CLASS_M1(TCellSelectCommand,
  2835.                    Inherited);
  2836.  
  2837. //----------------------------------------------------------------------------------------
  2838. // TCellSelectCommand constructor
  2839. //----------------------------------------------------------------------------------------
  2840. #pragma segment GVSelCommand
  2841.  
  2842. TCellSelectCommand::TCellSelectCommand()
  2843. {
  2844.     fAnchorCell = gZeroPt;                        // At least set it to something 
  2845.     fCommandKey = FALSE;
  2846.     fDeselecting = FALSE;
  2847.     fDifference = NULL;
  2848.     fGridView = NULL;
  2849.     fPreviousCell = CPoint(-1, -1);
  2850.     fPreviousSelection = NULL;
  2851.     fShiftKey = FALSE;
  2852.     fThisSelection = NULL;
  2853. }
  2854.  
  2855. //----------------------------------------------------------------------------------------
  2856. // TCellSelectCommand::ICellSelectCommand: 
  2857. //----------------------------------------------------------------------------------------
  2858. #pragma segment GVSelCommand
  2859.  
  2860. void TCellSelectCommand::ICellSelectCommand(TGridView* itsView,
  2861.                                             const VPoint& itsMouse,
  2862.                                             Boolean theShiftKey,
  2863.                                             Boolean theCommandKey)
  2864. {
  2865.     ITracker(cNoCommand, itsView, kCantUndo, kDoesNotCauseChange, NULL, itsView, itsView->GetScroller(kAnySuperView), itsMouse);
  2866.     fShiftKey = theShiftKey;
  2867.     fCommandKey = theCommandKey;
  2868.     fViewConstrain = FALSE;
  2869.  
  2870.     fGridView = itsView;
  2871.  
  2872.     FailInfo fi;
  2873.     Try(fi)
  2874.     {
  2875.         fPreviousSelection = MakeNewRgn();
  2876.         CopyRgn(fGridView->fSelections, fPreviousSelection);
  2877.         fThisSelection = fGridView->fHLRegion;
  2878.         SetEmptyRgn(fThisSelection);
  2879.         fDifference = MakeNewRgn();
  2880.         fi.Success();
  2881.     }
  2882.     else                                        // Recover
  2883.     {
  2884.         Free();
  2885.         fi.ReSignal();
  2886.     }
  2887. }
  2888.  
  2889. //----------------------------------------------------------------------------------------
  2890. // TCellSelectCommand::Free: 
  2891. //----------------------------------------------------------------------------------------
  2892. #pragma segment GVDoCommand
  2893.  
  2894. TCellSelectCommand::~TCellSelectCommand()
  2895. {
  2896.     fPreviousSelection = DisposeIfRgnHandle(fPreviousSelection);
  2897.     fDifference = DisposeIfRgnHandle(fDifference);
  2898.  
  2899.     fThisSelection = NULL;                        // I don't own it so I don't dispose it.
  2900.     // But, I sure don't need a reference to
  2901.     // it any more.
  2902. }
  2903.  
  2904. //----------------------------------------------------------------------------------------
  2905. // TCellSelectCommand::ComputeAnchorCell: 
  2906. //----------------------------------------------------------------------------------------
  2907. #pragma segment GVDoCommand
  2908.  
  2909. void TCellSelectCommand::ComputeAnchorCell(GridCell& clickedCell)
  2910. {
  2911.     fAnchorCell = clickedCell;
  2912.  
  2913.     if (fShiftKey && (!EmptyRgn(fPreviousSelection)))
  2914.     {
  2915.         const CRect& bounds = (**fPreviousSelection).rgnBBox;
  2916.  
  2917.         if (fAnchorCell.h >= bounds.left)
  2918.             fAnchorCell.h = bounds.left;
  2919.         else
  2920.             fAnchorCell.h = bounds.right - 1;
  2921.         if (fAnchorCell.v >= bounds.top)
  2922.             fAnchorCell.v = bounds.top;
  2923.         else
  2924.             fAnchorCell.v = bounds.bottom - 1;
  2925.     }
  2926. }
  2927.  
  2928. //----------------------------------------------------------------------------------------
  2929. // TCellSelectCommand::ComputeNewSelection: 
  2930. //----------------------------------------------------------------------------------------
  2931. #pragma segment GVDoCommand
  2932.  
  2933. void TCellSelectCommand::ComputeNewSelection(GridCell& clickedCell)
  2934. {
  2935.     if (fGridView->CanSelectCell(clickedCell))
  2936.     {
  2937.         CRect r;
  2938.  
  2939.         if (fGridView->fSingleSelection || (!fShiftKey))
  2940.             SetRect(r, clickedCell.h, clickedCell.v, clickedCell.h + 1, clickedCell.v + 1);
  2941.         else
  2942.         {
  2943.             Pt2Rect(fAnchorCell, clickedCell, r);
  2944.             ++r.right;
  2945.             ++r.bottom;
  2946.         }
  2947.         RectRgn(fThisSelection, r);
  2948.         if (fCommandKey && (!fGridView->fSingleSelection))
  2949.             if (fDeselecting)
  2950.                 DiffRgn(fPreviousSelection, fThisSelection, fThisSelection);
  2951.             else
  2952.                 UnionRgn(fPreviousSelection, fThisSelection, fThisSelection);
  2953.     }
  2954. }
  2955.  
  2956. //----------------------------------------------------------------------------------------
  2957. // TCellSelectCommand::HighlightNewSelection: 
  2958. //----------------------------------------------------------------------------------------
  2959. #pragma segment GVDoCommand
  2960.  
  2961. void TCellSelectCommand::HighlightNewSelection()
  2962. {
  2963.     // Turn off previously selected cells 
  2964.     DiffRgn(fPreviousSelection, fThisSelection, fDifference);
  2965.     fGridView->HighlightCells(fDifference, hlOn, hlOff);
  2966.  
  2967.     // Turn on newly selected cells
  2968.     DiffRgn(fThisSelection, fPreviousSelection, fDifference);
  2969.     fGridView->HighlightCells(fDifference, hlOff, hlOn);
  2970. }
  2971.  
  2972. //----------------------------------------------------------------------------------------
  2973. // TCellSelectCommand::TrackFeedback: 
  2974. //----------------------------------------------------------------------------------------
  2975. #pragma segment GVDoCommand
  2976.  
  2977. void TCellSelectCommand::TrackFeedback(TrackPhase/* aTrackPhase */ ,
  2978.                                        const VPoint&/* anchorPoint */  ,
  2979.                                        const VPoint&/* previousPoint */  ,
  2980.                                        const VPoint&/* nextPoint */  ,
  2981.                                        Boolean    /* mouseDidMove */,
  2982.                                        Boolean    /* turnItOn */)// override 
  2983. {
  2984. }
  2985.  
  2986. //----------------------------------------------------------------------------------------
  2987. // TCellSelectCommand::TrackMouse: 
  2988. //----------------------------------------------------------------------------------------
  2989. #pragma segment GVDoCommand
  2990.  
  2991. TTracker* TCellSelectCommand::TrackMouse(TrackPhase aTrackPhase,
  2992.                                          VPoint&/* anchorPoint */  ,
  2993.                                          VPoint&/* previousPoint */  ,
  2994.                                          VPoint& nextPoint,
  2995.                                          Boolean mouseDidMove)// override 
  2996. {
  2997.     if (mouseDidMove)
  2998.     {
  2999.         VPoint clippedPoint(nextPoint);
  3000.  
  3001.         clippedPoint.ConstrainTo(fGridView->GetExtent());
  3002.         GridCell clickedCell = fGridView->VPointToCell(clippedPoint);
  3003.         if (aTrackPhase == trackBegin)
  3004.         {
  3005.             ComputeAnchorCell(clickedCell);
  3006.             if (fCommandKey)
  3007.                 fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
  3008.         }
  3009.  
  3010.         if (clickedCell != fPreviousCell)
  3011.         {
  3012.             ComputeNewSelection(clickedCell);
  3013.             HighlightNewSelection();
  3014.  
  3015.             CopyRgn(fThisSelection, fPreviousSelection);
  3016.             fPreviousCell = clickedCell;
  3017.         }
  3018.     }
  3019.     return this;
  3020. }
  3021.  
  3022. //----------------------------------------------------------------------------------------
  3023. // TCellSelectCommand::DoIt: 
  3024. //----------------------------------------------------------------------------------------
  3025. #pragma segment GVDoCommand
  3026.  
  3027. void TCellSelectCommand::DoIt()                    // override 
  3028. {
  3029.     if (fGridView->fSingleSelection)
  3030.         fGridView->SelectCell(((CRect &)(*fThisSelection)->rgnBBox)[topLeft], kDontExtend, kDontHighlight, kSelect);
  3031.     else
  3032.         fGridView->SetSelection(fThisSelection, kDontExtend, kDontHighlight, kSelect);
  3033. }
  3034.  
  3035.  
  3036. //========================================================================================
  3037. // CLASS TRCSelectCommand
  3038. //========================================================================================
  3039. #undef Inherited
  3040. #define Inherited TCellSelectCommand
  3041.  
  3042. #pragma segment GVSelCommand
  3043. MA_DEFINE_CLASS_M1(TRCSelectCommand,
  3044.                    Inherited);
  3045.  
  3046. //----------------------------------------------------------------------------------------
  3047. // TRCSelectCommand::TRCSelectCommand: Empty constructor to satisfy the compiler.
  3048. //----------------------------------------------------------------------------------------
  3049. #pragma segment ConstructorRes
  3050.  
  3051. TRCSelectCommand::TRCSelectCommand()
  3052. {
  3053. }
  3054.  
  3055. //----------------------------------------------------------------------------------------
  3056. // TRCSelectCommand destructor
  3057. //----------------------------------------------------------------------------------------
  3058. #pragma segment MADestructorRes
  3059.  
  3060. TRCSelectCommand::~TRCSelectCommand()
  3061. {
  3062. }
  3063.  
  3064. //----------------------------------------------------------------------------------------
  3065. // TRCSelectCommand::IRCSelectCommand: 
  3066. //----------------------------------------------------------------------------------------
  3067. #pragma segment GVSelCommand
  3068.  
  3069. void TRCSelectCommand::IRCSelectCommand(TGridView* itsView,
  3070.                                         const VPoint& itsMouse,
  3071.                                         Boolean theShiftKey,
  3072.                                         Boolean theCommandKey)
  3073. {
  3074.     ICellSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
  3075. }
  3076.  
  3077. //----------------------------------------------------------------------------------------
  3078. // TRCSelectCommand::ComputeNewSelection: 
  3079. //----------------------------------------------------------------------------------------
  3080. #pragma segment GVDoCommand
  3081.  
  3082. void TRCSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override 
  3083. {
  3084.     if (fGridView->CanSelectCell(clickedCell))
  3085.     {
  3086.         CRect r;
  3087.  
  3088.         if (fGridView->fSingleSelection)
  3089.             r = CRect(clickedCell.h, clickedCell.v, clickedCell.h + 1, clickedCell.v + 1);
  3090.         else
  3091.         {
  3092.             Pt2Rect(fAnchorCell, clickedCell, r);
  3093.             ++r.right;
  3094.             ++r.bottom;
  3095.         }
  3096.         RectRgn(fThisSelection, r);
  3097.         if (fCommandKey && (!fGridView->fSingleSelection))
  3098.             if (fDeselecting)
  3099.                 DiffRgn(fPreviousSelection, fThisSelection, fThisSelection);
  3100.             else
  3101.                 UnionRgn(fPreviousSelection, fThisSelection, fThisSelection);
  3102.     }
  3103. }
  3104.  
  3105. //----------------------------------------------------------------------------------------
  3106. // TRCSelectCommand::TrackMouse: 
  3107. //----------------------------------------------------------------------------------------
  3108. #pragma segment GVDoCommand
  3109.  
  3110. TTracker* TRCSelectCommand::TrackMouse(TrackPhase aTrackPhase,
  3111.                                        VPoint&    /* anchorPoint */ ,
  3112.                                        VPoint&    /* previousPoint */ ,
  3113.                                        VPoint& nextPoint,
  3114.                                        Boolean mouseDidMove)// override 
  3115. {
  3116.     if (mouseDidMove)
  3117.     {
  3118.         VPoint clippedPoint(nextPoint);
  3119.         clippedPoint.ConstrainTo(fGridView->GetExtent());
  3120.         GridCell clickedCell = fGridView->VPointToCell(clippedPoint);
  3121.         if (aTrackPhase == trackBegin)
  3122.         {
  3123.             ComputeAnchorCell(clickedCell);
  3124.             if (fCommandKey)
  3125.                 fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
  3126.         }
  3127.  
  3128.         if (clickedCell != fPreviousCell)
  3129.         {
  3130.             if (!fShiftKey && (aTrackPhase != trackBegin))
  3131.             {
  3132.                 ComputeAnchorCell(clickedCell);
  3133.                 if (fCommandKey)
  3134.                     fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
  3135.             }
  3136.             ComputeNewSelection(clickedCell);
  3137.             HighlightNewSelection();
  3138.  
  3139.             CopyRgn(fThisSelection, fPreviousSelection);
  3140.             fPreviousCell = clickedCell;
  3141.         }
  3142.     }
  3143.     return this;
  3144. }
  3145.  
  3146.  
  3147. //========================================================================================
  3148. // CLASS TRowSelectCommand
  3149. //========================================================================================
  3150. #undef Inherited
  3151. #define Inherited TRCSelectCommand
  3152.  
  3153. #pragma segment GVSelCommand
  3154. MA_DEFINE_CLASS_M1(TRowSelectCommand,
  3155.                    Inherited);
  3156.  
  3157. //----------------------------------------------------------------------------------------
  3158. // TRowSelectCommand::TRowSelectCommand: Empty constructor to satisfy the compiler.
  3159. //----------------------------------------------------------------------------------------
  3160. #pragma segment ConstructorRes
  3161.  
  3162. TRowSelectCommand::TRowSelectCommand()
  3163. {
  3164. }
  3165.  
  3166. //----------------------------------------------------------------------------------------
  3167. // TRowSelectCommand destructor
  3168. //----------------------------------------------------------------------------------------
  3169. #pragma segment MADestructorRes
  3170.  
  3171. TRowSelectCommand::~TRowSelectCommand()
  3172. {
  3173. }
  3174.  
  3175. //----------------------------------------------------------------------------------------
  3176. // TRowSelectCommand::IRowSelectCommand: 
  3177. //----------------------------------------------------------------------------------------
  3178. #pragma segment GVSelCommand
  3179.  
  3180. void TRowSelectCommand::IRowSelectCommand(TGridView* itsView,
  3181.                                           const VPoint& itsMouse,
  3182.                                           Boolean theShiftKey,
  3183.                                           Boolean theCommandKey)
  3184. {
  3185.     IRCSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
  3186. }
  3187.  
  3188. //----------------------------------------------------------------------------------------
  3189. // TRowSelectCommand::ComputeAnchorCell: 
  3190. //----------------------------------------------------------------------------------------
  3191. #pragma segment GVDoCommand
  3192.  
  3193. void TRowSelectCommand::ComputeAnchorCell(GridCell& clickedCell)// override 
  3194. {
  3195.     Inherited::ComputeAnchorCell(clickedCell);
  3196.     fAnchorCell.h = 1;
  3197. }
  3198.  
  3199. //----------------------------------------------------------------------------------------
  3200. // TRowSelectCommand::ComputeNewSelection: 
  3201. //----------------------------------------------------------------------------------------
  3202. #pragma segment GVDoCommand
  3203.  
  3204. void TRowSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override 
  3205. {
  3206.     clickedCell.h = fGridView->fNumOfCols;
  3207.  
  3208.     Inherited::ComputeNewSelection(clickedCell);
  3209. }
  3210.  
  3211.  
  3212. //========================================================================================
  3213. // CLASS TColumnSelectCommand
  3214. //========================================================================================
  3215. #undef Inherited
  3216. #define Inherited TRCSelectCommand
  3217.  
  3218. #pragma segment GVSelCommand
  3219. MA_DEFINE_CLASS_M1(TColumnSelectCommand,
  3220.                    Inherited);
  3221.  
  3222. //----------------------------------------------------------------------------------------
  3223. // TColumnSelectCommand::TColumnSelectCommand: Empty constructor to satisfy the compiler.
  3224. //----------------------------------------------------------------------------------------
  3225. #pragma segment ConstructorRes
  3226.  
  3227. TColumnSelectCommand::TColumnSelectCommand()
  3228. {
  3229. }
  3230.  
  3231. //----------------------------------------------------------------------------------------
  3232. // TColumnSelectCommand destructor
  3233. //----------------------------------------------------------------------------------------
  3234. #pragma segment MADestructorRes
  3235.  
  3236. TColumnSelectCommand::~TColumnSelectCommand()
  3237. {
  3238. }
  3239.  
  3240. //----------------------------------------------------------------------------------------
  3241. // TColumnSelectCommand::IColumnSelectCommand: 
  3242. //----------------------------------------------------------------------------------------
  3243. #pragma segment GVSelCommand
  3244.  
  3245. void TColumnSelectCommand::IColumnSelectCommand(TGridView* itsView,
  3246.                                                 const VPoint& itsMouse,
  3247.                                                 Boolean theShiftKey,
  3248.                                                 Boolean theCommandKey)
  3249. {
  3250.     IRCSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
  3251. }
  3252.  
  3253. //----------------------------------------------------------------------------------------
  3254. // TColumnSelectCommand::ComputeAnchorCell: 
  3255. //----------------------------------------------------------------------------------------
  3256. #pragma segment GVDoCommand
  3257.  
  3258. void TColumnSelectCommand::ComputeAnchorCell(GridCell& clickedCell)// override 
  3259. {
  3260.     Inherited::ComputeAnchorCell(clickedCell);
  3261.  
  3262.     fAnchorCell.v = 1;
  3263. }
  3264.  
  3265. //----------------------------------------------------------------------------------------
  3266. // TColumnSelectCommand::ComputeNewSelection: 
  3267. //----------------------------------------------------------------------------------------
  3268. #pragma segment GVDoCommand
  3269.  
  3270. void TColumnSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override 
  3271. {
  3272.     clickedCell.v = fGridView->fNumOfRows;
  3273.  
  3274.     Inherited::ComputeNewSelection(clickedCell);
  3275. }
  3276.  
  3277.  
  3278. //========================================================================================
  3279. // CLASS CRowIterator
  3280. //========================================================================================
  3281. #undef Inherited
  3282. #define Inherited CIterator
  3283.  
  3284. const short CRowIterator::kNullRow = -1;
  3285.  
  3286. //----------------------------------------------------------------------------------------
  3287. // CRowIterator::CRowIterator:
  3288. //----------------------------------------------------------------------------------------
  3289. #pragma segment IteratorRes
  3290.  
  3291. CRowIterator::CRowIterator(const TGridView* itsGridView,
  3292.                            short startRow,
  3293.                            short stopRow,
  3294.                            Boolean itsForward)
  3295. {
  3296.     IRowIterator(itsGridView, startRow, stopRow, itsForward);
  3297. }
  3298.  
  3299.  
  3300. //----------------------------------------------------------------------------------------
  3301. // CRowIterator::CRowIterator: 
  3302. //----------------------------------------------------------------------------------------
  3303. #pragma segment IteratorRes
  3304.  
  3305. CRowIterator::CRowIterator(const TGridView* itsGridView,
  3306.                            Boolean itsForward)
  3307. {
  3308.     IRowIterator(itsGridView, 1, itsGridView->fNumOfRows, itsForward);
  3309. }
  3310.  
  3311.  
  3312. //----------------------------------------------------------------------------------------
  3313. // CRowIterator::CRowIterator: 
  3314. //----------------------------------------------------------------------------------------
  3315. #pragma segment IteratorRes
  3316.  
  3317. CRowIterator::CRowIterator(const TGridView* itsGridView)
  3318. {
  3319.     IRowIterator(itsGridView, 1, itsGridView->fNumOfRows, kIterateForward);
  3320. }
  3321.  
  3322.  
  3323. //----------------------------------------------------------------------------------------
  3324. // CRowIterator::IRowIterator: 
  3325. //----------------------------------------------------------------------------------------
  3326. #pragma segment IteratorRes
  3327.  
  3328. void CRowIterator::IRowIterator(const TGridView* itsGridView,
  3329.                                 short startRow,
  3330.                                 short stopRow,
  3331.                                 Boolean itsForward)
  3332. {
  3333.     if (itsGridView)
  3334.     {
  3335.         fFirstRow = (short)Max(1, startRow);    //!!! Cast
  3336.         fLastRow = (short)Min(itsGridView->fNumOfRows, stopRow);//!!! Cast
  3337.         fIterateForward = itsForward;
  3338.         Reset();                                // this sets it to the beginning
  3339.     }
  3340.     else
  3341.     {
  3342.         fFirstRow = kNullRow;
  3343.         fLastRow = kNullRow;
  3344.         fIterateForward = kIterateForward;
  3345.         Reset();                                // this sets it to the beginning
  3346.     }
  3347. }
  3348.  
  3349.  
  3350. //----------------------------------------------------------------------------------------
  3351. // CRowIterator::FirstRow: 
  3352. //----------------------------------------------------------------------------------------
  3353. #pragma segment IteratorRes
  3354.  
  3355. short CRowIterator::FirstRow()
  3356. {
  3357.     Reset();
  3358.     return fCurrentRow;
  3359. }
  3360.  
  3361.  
  3362. //----------------------------------------------------------------------------------------
  3363. // CRowIterator::NextRow: 
  3364. //----------------------------------------------------------------------------------------
  3365. #pragma segment IteratorRes
  3366.  
  3367. short CRowIterator::NextRow()
  3368. {
  3369.     if (More())                                    // don't advance if we're at the end of the road!
  3370.         Advance();
  3371.     return fCurrentRow;
  3372. }
  3373.  
  3374.  
  3375. //----------------------------------------------------------------------------------------
  3376. // CRowIterator::More: 
  3377. //----------------------------------------------------------------------------------------
  3378. #pragma segment IteratorRes
  3379.  
  3380. Boolean CRowIterator::More()
  3381. {
  3382.     return (fCurrentRow != kNullRow);
  3383. }
  3384.  
  3385.  
  3386. //----------------------------------------------------------------------------------------
  3387. // CRowIterator::Reset: 
  3388. //----------------------------------------------------------------------------------------
  3389. #pragma segment IteratorRes
  3390.  
  3391. void CRowIterator::Reset()
  3392. {
  3393.     if (fFirstRow <= fLastRow)
  3394.         fCurrentRow = fIterateForward ? fFirstRow : fLastRow;
  3395.     else
  3396.         fCurrentRow = kNullRow;                    // there is nothing to iterate over!
  3397. }
  3398.  
  3399. //----------------------------------------------------------------------------------------
  3400. // CRowIterator::Advance: 
  3401. //----------------------------------------------------------------------------------------
  3402. #pragma segment IteratorRes
  3403.  
  3404. void CRowIterator::Advance()
  3405. {
  3406.     //This assumes that More() is false -- otherwise Advance() may start iterating
  3407.     //from 0, since kNullRow is most probably less than fLastRow
  3408.     if (fIterateForward)
  3409.         fCurrentRow = (fCurrentRow < fLastRow) ? fCurrentRow + 1 : kNullRow;
  3410.     else
  3411.         fCurrentRow = (fCurrentRow > fFirstRow) ? fCurrentRow - 1 : kNullRow;
  3412. }
  3413.  
  3414.  
  3415. //========================================================================================
  3416. // CLASS CColumnIterator
  3417. //========================================================================================
  3418. #undef Inherited
  3419. #define Inherited CIterator
  3420.  
  3421. const short CColumnIterator::kNullColumn = -1;
  3422.  
  3423. //----------------------------------------------------------------------------------------
  3424. // CColumnIterator::CColumnIterator:
  3425. //----------------------------------------------------------------------------------------
  3426. #pragma segment IteratorRes
  3427.  
  3428. CColumnIterator::CColumnIterator(const TGridView* itsGridView,
  3429.                                  short startColumn,
  3430.                                  short stopColumn,
  3431.                                  Boolean itsForward)
  3432. {
  3433.     IColumnIterator(itsGridView, startColumn, stopColumn, itsForward);
  3434. }
  3435.  
  3436. //----------------------------------------------------------------------------------------
  3437. // CColumnIterator::CColumnIterator: 
  3438. //----------------------------------------------------------------------------------------
  3439. #pragma segment IteratorRes
  3440.  
  3441. CColumnIterator::CColumnIterator(const TGridView* itsGridView,
  3442.                                  Boolean itsForward)
  3443. {
  3444.     IColumnIterator(itsGridView, 1, itsGridView->fNumOfCols, itsForward);
  3445. }
  3446.  
  3447. //----------------------------------------------------------------------------------------
  3448. // CColumnIterator::CColumnIterator: 
  3449. //----------------------------------------------------------------------------------------
  3450. #pragma segment IteratorRes
  3451.  
  3452. CColumnIterator::CColumnIterator(const TGridView* itsGridView)
  3453. {
  3454.     IColumnIterator(itsGridView, 1, itsGridView->fNumOfCols, kIterateForward);
  3455. }
  3456.  
  3457. //----------------------------------------------------------------------------------------
  3458. // CColumnIterator::IColumnIterator: 
  3459. //----------------------------------------------------------------------------------------
  3460. #pragma segment IteratorRes
  3461.  
  3462. void CColumnIterator::IColumnIterator(const TGridView* itsGridView,
  3463.                                       short startColumn,
  3464.                                       short stopColumn,
  3465.                                       Boolean itsForward)
  3466. {
  3467.     if (itsGridView)
  3468.     {
  3469.         fFirstColumn = (short)Max(1, startColumn);//!!! Cast
  3470.         fLastColumn = (short)Min(itsGridView->fNumOfCols, stopColumn);//!!! Cast
  3471.         fIterateForward = itsForward;
  3472.         Reset();                                // this sets it to the beginning
  3473.     }
  3474.     else
  3475.     {
  3476.         fFirstColumn = kNullColumn;
  3477.         fLastColumn = kNullColumn;
  3478.         fIterateForward = kIterateForward;
  3479.         Reset();                                // this sets it to the beginning
  3480.     }
  3481. }
  3482.  
  3483. //----------------------------------------------------------------------------------------
  3484. // CColumnIterator::FirstColumn: 
  3485. //----------------------------------------------------------------------------------------
  3486. #pragma segment IteratorRes
  3487.  
  3488. short CColumnIterator::FirstColumn()
  3489. {
  3490.     Reset();
  3491.     return fCurrentColumn;
  3492. }
  3493.  
  3494. //----------------------------------------------------------------------------------------
  3495. // CColumnIterator::NextColumn: 
  3496. //----------------------------------------------------------------------------------------
  3497. #pragma segment IteratorRes
  3498.  
  3499. short CColumnIterator::NextColumn()
  3500. {
  3501.     if (More())                                    // don't advance if we're at the end of the road!
  3502.         Advance();
  3503.     return fCurrentColumn;
  3504. }
  3505.  
  3506. //----------------------------------------------------------------------------------------
  3507. // CColumnIterator::More: 
  3508. //----------------------------------------------------------------------------------------
  3509. #pragma segment IteratorRes
  3510.  
  3511. Boolean CColumnIterator::More()
  3512. {
  3513.     return (fCurrentColumn != kNullColumn);
  3514. }
  3515.  
  3516. //----------------------------------------------------------------------------------------
  3517. // CColumnIterator::Reset: 
  3518. //----------------------------------------------------------------------------------------
  3519. #pragma segment IteratorRes
  3520.  
  3521. void CColumnIterator::Reset()
  3522. {
  3523.     if (fFirstColumn <= fLastColumn)
  3524.         fCurrentColumn = fIterateForward ? fFirstColumn : fLastColumn;
  3525.     else
  3526.         fCurrentColumn = kNullColumn;            // there is nothing to iterate over!
  3527. }
  3528.  
  3529. //----------------------------------------------------------------------------------------
  3530. // CColumnIterator::Advance: 
  3531. //----------------------------------------------------------------------------------------
  3532. #pragma segment IteratorRes
  3533.  
  3534. void CColumnIterator::Advance()
  3535. {
  3536.     //This assumes that More() is false -- otherwise Advance() may start iterating
  3537.     //from 0, since kNullRow is most probably less than fLastRow
  3538.     if (fIterateForward)
  3539.         fCurrentColumn = (fCurrentColumn < fLastColumn) ? fCurrentColumn + 1 : kNullColumn;
  3540.     else
  3541.         fCurrentColumn = (fCurrentColumn > fFirstColumn) ? fCurrentColumn - 1 : kNullColumn;
  3542. }
  3543.  
  3544.  
  3545. //========================================================================================
  3546. // CLASS CCellIterator
  3547. //========================================================================================
  3548. #undef Inherited
  3549. #define Inherited CIterator
  3550.  
  3551. const GridCell CCellIterator::kNullCell = GridCell(-1, -1);
  3552. const Boolean CCellIterator::kIterateRowMajor = TRUE;
  3553.  
  3554. //----------------------------------------------------------------------------------------
  3555. // CCellIterator::CCellIterator:
  3556. //----------------------------------------------------------------------------------------
  3557. #pragma segment IteratorRes
  3558.  
  3559. CCellIterator::CCellIterator(const TGridView* itsGridView,
  3560.                              GridCell startCell,
  3561.                              GridCell stopCell,
  3562.                              Boolean itsRowForward,
  3563.                              Boolean itsColumnForward,
  3564.                              Boolean itsRowMajor) :
  3565.     // initialize the Row and Column Iterators first!
  3566.     fRowIterator(itsGridView, startCell.v, stopCell.v, itsRowForward),
  3567.     fColumnIterator(itsGridView, startCell.h, stopCell.h, itsColumnForward)
  3568.  
  3569. {
  3570.     fIterateRowMajor = itsRowMajor;                // don't worry about whether or not
  3571.     // itsGridView is valid -- let the Row and
  3572.     // Column Iterators worry about it.
  3573. }
  3574. // CCellIterator::CCellIterator 
  3575.  
  3576. //----------------------------------------------------------------------------------------
  3577. // CCellIterator::CCellIterator: 
  3578. //----------------------------------------------------------------------------------------
  3579. #pragma segment IteratorRes
  3580.  
  3581. CCellIterator::CCellIterator(const TGridView* itsGridView,
  3582.                              Boolean itsRowForward,
  3583.                              Boolean itsColumnForward,
  3584.                              Boolean itsRowMajor) :
  3585.     // initialize the Row and Column Iterators first!
  3586.     fRowIterator(itsGridView, itsRowForward),
  3587.     fColumnIterator(itsGridView, itsColumnForward)
  3588. {
  3589.     fIterateRowMajor = itsRowMajor;                // don't worry about whether or not
  3590.     // itsGridView is valid -- let the Row and
  3591.     // Column Iterators worry about it.
  3592. }
  3593. // CCellIterator::CCellIterator 
  3594.  
  3595. //----------------------------------------------------------------------------------------
  3596. // CCellIterator::CCellIterator: 
  3597. //----------------------------------------------------------------------------------------
  3598. #pragma segment IteratorRes
  3599.  
  3600. CCellIterator::CCellIterator(const TGridView* itsGridView) :
  3601.     // initialize the Row and Column Iterators first!
  3602.     fRowIterator(itsGridView),
  3603.     fColumnIterator(itsGridView)
  3604. {
  3605.     fIterateRowMajor = kIterateRowMajor;        // don't worry about whether or not
  3606.     // itsGridView is valid -- let the Row and
  3607.     // Column Iterators worry about it.
  3608. }
  3609. // CCellIterator::CCellIterator 
  3610.  
  3611. //----------------------------------------------------------------------------------------
  3612. // CCellIterator::FirstCell: 
  3613. //----------------------------------------------------------------------------------------
  3614. #pragma segment IteratorRes
  3615.  
  3616. GridCell CCellIterator::FirstCell()
  3617. {
  3618.     Reset();
  3619.     return fCurrentCell;
  3620. }
  3621.  
  3622. //----------------------------------------------------------------------------------------
  3623. // CCellIterator::NextCell: 
  3624. //----------------------------------------------------------------------------------------
  3625. #pragma segment IteratorRes
  3626.  
  3627. GridCell CCellIterator::NextCell()
  3628. {
  3629.     Advance();
  3630.     return fCurrentCell;
  3631. }
  3632.  
  3633. //----------------------------------------------------------------------------------------
  3634. // CCellIterator::More: 
  3635. //----------------------------------------------------------------------------------------
  3636. #pragma segment IteratorRes
  3637.  
  3638. Boolean CCellIterator::More()
  3639. {
  3640.     return (fRowIterator.More() || fColumnIterator.More());
  3641. }
  3642.  
  3643. //----------------------------------------------------------------------------------------
  3644. // CCellIterator::Reset: 
  3645. //----------------------------------------------------------------------------------------
  3646. #pragma segment IteratorRes
  3647.  
  3648. void CCellIterator::Reset()
  3649. {
  3650.     fCurrentCell.v = fRowIterator.FirstRow();
  3651.     fCurrentCell.h = fColumnIterator.FirstColumn();
  3652. }
  3653.  
  3654. //----------------------------------------------------------------------------------------
  3655. // CCellIterator::Advance: 
  3656. //----------------------------------------------------------------------------------------
  3657. #pragma segment IteratorRes
  3658.  
  3659. void CCellIterator::Advance()
  3660. {
  3661.     if (fIterateRowMajor)
  3662.     {
  3663.         fCurrentCell.h = fColumnIterator.NextColumn();//advance the column
  3664.         if (!fColumnIterator.More())
  3665.         {
  3666.             fCurrentCell.v = fRowIterator.NextRow();//advance the row
  3667.             if (fRowIterator.More())            //must go through the columns again
  3668.                 fCurrentCell.h = fColumnIterator.FirstColumn();
  3669.         }
  3670.     }
  3671.     else
  3672.     {
  3673.         fCurrentCell.v = fRowIterator.NextRow();//advance the row
  3674.         if (!fRowIterator.More())
  3675.         {
  3676.             fCurrentCell.h = fColumnIterator.NextColumn();//advance the column
  3677.             if (fColumnIterator.More())            //must go through the rows again
  3678.                 fCurrentCell.v = fRowIterator.FirstRow();
  3679.         }
  3680.     }
  3681. }
  3682.  
  3683.  
  3684.  
  3685. //========================================================================================
  3686. // CLASS CCellInRegionIterator
  3687. //========================================================================================
  3688. #undef Inherited
  3689. #define Inherited CCellIterator
  3690.  
  3691. //----------------------------------------------------------------------------------------
  3692. // CCellInRegionIterator::CCellInRegionIterator: an iterator class designed to replace the
  3693. // EachInRegion method of TGridView. APW 7-15
  3694. //----------------------------------------------------------------------------------------
  3695. #pragma segment IteratorRes
  3696.  
  3697. CCellInRegionIterator::CCellInRegionIterator(const TGridView* itsGridView,
  3698.                                              RgnHandle aRegion,
  3699.                                              Boolean itsRowForward,
  3700.                                              Boolean itsColumnForward,
  3701.                                              Boolean itsRowMajor) :
  3702.     CCellIterator(itsGridView, ((CRect &)(*aRegion)->rgnBBox)[topLeft], ((CRect &)(*aRegion)->rgnBBox)[botRight] - CPoint(1, 1), itsRowForward, itsColumnForward, itsRowMajor)
  3703. {
  3704.     fIsRectangularRegion = ((**aRegion).rgnSize == 10);// it's a Rectangle
  3705.     fRegion = aRegion;
  3706. }
  3707. // CCellInRegionIterator::CCellInRegionIterator 
  3708.  
  3709. //----------------------------------------------------------------------------------------
  3710. // CCellInRegionIterator::CCellInRegionIterator: 
  3711. //----------------------------------------------------------------------------------------
  3712. #pragma segment IteratorRes
  3713.  
  3714. CCellInRegionIterator::CCellInRegionIterator(const TGridView* itsGridView,
  3715.                                              RgnHandle aRegion) :
  3716.     CCellIterator(itsGridView, ((CRect &)(*aRegion)->rgnBBox)[topLeft], ((CRect &)(*aRegion)->rgnBBox)[botRight] - CPoint(1, 1), kIterateForward, kIterateForward, kIterateRowMajor)
  3717. {
  3718.     fIsRectangularRegion = ((**aRegion).rgnSize == 10);// it's a Rectangle
  3719.     fRegion = aRegion;
  3720. }
  3721. // CCellInRegionIterator::CCellInRegionIterator 
  3722.  
  3723. //----------------------------------------------------------------------------------------
  3724. // CCellInRegionIterator::Reset: 
  3725. //----------------------------------------------------------------------------------------
  3726. #pragma segment IteratorRes
  3727.  
  3728. void CCellInRegionIterator::Reset()                //override!
  3729. {
  3730.     CCellIterator::Reset();                        // should be Inherited::Reset
  3731.  
  3732.     if (!fIsRectangularRegion)                    // if it's rectangular, all cells are in
  3733.     // the region.
  3734.     {
  3735.         if ((More()) && !CellIsInRegion())        // Otherwise, check to see if it's in the
  3736.         // region.
  3737.             Advance();                            // This is now guaranteed to be a selected
  3738.         // cell
  3739.     }
  3740. }
  3741.  
  3742. //----------------------------------------------------------------------------------------
  3743. // CCellInRegionIterator::Advance: 
  3744. //----------------------------------------------------------------------------------------
  3745. #pragma segment IteratorRes
  3746. void CCellInRegionIterator::Advance()            //override!
  3747.  
  3748. {
  3749.     CCellIterator::Advance();                    //first advance
  3750.  
  3751.     if (!fIsRectangularRegion)                    // do we have to check to see if it is
  3752.     // selected?
  3753.     {
  3754.         while ((More()) && !CellIsInRegion())
  3755.         {
  3756.             // Yes, so while we have an
  3757.             // unselected cell, keep 
  3758.             // iterating until we
  3759.             CCellIterator::Advance();            // run out or find one.
  3760.         }
  3761.     }
  3762. }
  3763.  
  3764. //----------------------------------------------------------------------------------------
  3765. // CCellInRegionIterator::CellIsInRegion: 
  3766. //----------------------------------------------------------------------------------------
  3767. #pragma segment IteratorRes
  3768. Boolean CCellInRegionIterator::CellIsInRegion()
  3769.  
  3770. {
  3771.     return PtInRgn(fCurrentCell, fRegion);
  3772. }
  3773.  
  3774.  
  3775. //========================================================================================
  3776. // CLASS CSelectedCellIterator
  3777. //========================================================================================
  3778. #undef Inherited
  3779. #define Inherited CCellInRegionIterator
  3780.  
  3781. //----------------------------------------------------------------------------------------
  3782. // CSelectedCellIterator::CSelectedCellIterator: an iterator class designed to replace the
  3783. // EachSelectedCellDo method of TGridView. APW 7-15
  3784. //----------------------------------------------------------------------------------------
  3785. #pragma segment IteratorRes
  3786. CSelectedCellIterator::CSelectedCellIterator(const TGridView* itsGridView,
  3787.                                              Boolean itsRowForward,
  3788.                                              Boolean itsColumnForward,
  3789.                                              Boolean itsRowMajor) :
  3790.     CCellInRegionIterator(itsGridView, itsGridView->fSelections, itsRowForward, itsColumnForward, itsRowMajor)
  3791. {
  3792. }
  3793. // CSelectedCellIterator::CSelectedCellIterator 
  3794.  
  3795. //----------------------------------------------------------------------------------------
  3796. // CSelectedCellIterator::CSelectedCellIterator: 
  3797. //----------------------------------------------------------------------------------------
  3798. #pragma segment IteratorRes
  3799. CSelectedCellIterator::CSelectedCellIterator(const TGridView* itsGridView) :
  3800.     CCellInRegionIterator(itsGridView, itsGridView->fSelections)
  3801. {
  3802. }
  3803. // CSelectedCellIterator::CSelectedCellIterator 
  3804.  
  3805. //----------------------------------------------------------------------------------------
  3806. // CSelectedCellIterator::More: 
  3807. //----------------------------------------------------------------------------------------
  3808. #pragma segment IteratorRes
  3809. void CSelectedCellIterator::Reset()
  3810. {
  3811.     // We don't really need to have an override for this method.  However
  3812.     // doing so fixes a problem with determing the "key function" of the class
  3813.     // that leads to duplicate definitions of the VTables in all files that include
  3814.     // this iterator or dump files that include it So for the time being use an implementation
  3815.     // that just calls inherited.
  3816.     Inherited::Reset();
  3817. }
  3818.  
  3819. //----------------------------------------------------------------------------------------
  3820. // End of UGridView.cp
  3821.  
  3822. #pragma segment Inline
  3823.